LOS ANGELES (AP) -- Chase McGrath kicked a 43-yard field goal in the second overtime after hitting a tying 31-yarder on the final snap of regulation, and No. 4 Southern California rallied for a wild 27-24 victory over Texas on Saturday night.
Sam Darnold passed for 397 yards and three touchdowns to help the Trojans (3-0) surge to their 12th consecutive victory.
Christian Rector forced a goal-line fumble by Texas quarterback Sam Ehlinger in the second overtime before USC's walk-on freshman kicker coolly ended it with the second field goal of his college career.
"We had to finish strong, and that's what we did," said USC receiver Deontay Burnett, who caught eight passes for 123 yards and two touchdowns.
After 55 minutes of defense-dominated football, both offenses erupted late to create a pretty decent sequel to these powerhouse programs' last meeting in the landmark 2006 Rose Bowl.
Ehlinger passed for 298 yards and led a 91-yard, go-ahead TD drive late in regulation for the Longhorns (1-2). The freshman quarterback from Austin grew up, but Texas was narrowly denied a huge win early in coach Tom Herman's debut season.
Ehlinger hit Armanti Foreman with a 17-yard touchdown pass with 45 seconds left, but McGrath tied it on the final snap of regulation after Darnold drove the Trojans 52 yards in about 30 seconds.
"The plays down the stretch by Sam and Deontay, I don't know if I'll ever forget in my life," USC coach Clay Helton said. "You hope for perfect execution, and that's what we got."
Burnett caught a 25-yard touchdown pass from Darnold on the first snap of overtime. Cade Brewer caught a short TD pass to cap Texas' first OT possession.
Texas reached the goal line in the second OT before Rector ripped the ball out of Ehlinger's hands while the freshman quarterback attempted to score. Ajene Harris recovered, but the Trojans' offense stalled before McGrath came through again.
"It's good to get a great win against such a great Texas team," Darnold said. "We gave it all we had. They gave it all they had. It was just a great win for our guys. We learned a lot of things about our offense. Good things, and things we've got to figure out."
Both defenses were in charge until late in Texas' first visit to the Coliseum in 50 years. The schools hadn't met since the Longhorns won the national title with a thrilling 41-38 victory in Pasadena.
Even with Vince Young and Matt Leinart in attendance, both current offenses showed no signs of replicating that beauty in the rematch -- until everything went crazy in the final minutes.
Texas: Once the heartache subsides, this will be an encouraging outing. The defense took some remarkable strides forward after giving up 51 points to Maryland in the season opener, and Ehlinger had moments of impressive play. Sure, the offense needs much more work, but this type of defensive performance will win a bunch of games in the Big 12.
USC: The Trojans' offense racked up 91 points and 1,144 yards in its first two games, but Texas largely shut it down. Darnold and his teammates rallied, but USC's defense deserves most of the credit for keeping them in a game that turned out to be much tougher than anybody expected.
The game was scoreless until 2:40 before halftime, when Burnett made a diving TD catch. The Longhorns tied it moments later when Darnold's perfect pass smacked off receiver Jalen Greene's hands and DeShon Elliott snatched it for a 38-yard TD interception return.
Instead of kneeling out the half, Darnold threw underneath Texas' prevent defense to Ronald Jones, who sprinted across the field for a 56-yard TD, getting a devastating block from receiver Steven Mitchell on the way in.
In the hyper-reactive world of September rankings, USC is likely to slide a bit in the Top 10 after struggling to hold on, even though its defense nearly posted a shutout for 59 minutes.
Texas: After a bye week, Big 12 play begins with a visit to Iowa State on Thursday, Sept. 28.
USC: The Trojans' road opener is at California on Saturday.