EUGENE, Ore. (AP) — Matt Barkley was confident that No. 18 USC was headed for an upset all along, even when fourth-ranked Oregon mounted a comeback.

“We expected to shock everybody except ourselves,” he said after throwing for 323 yards and four touchdowns in a 38-35 victory over the Ducks on Saturday night.

The loss snapped a 21-game winning streak for Oregon (9-2, 7-1 Pac-12) at Autzen Stadium, which was the longest in the nation. It also stopped a 19-game winning streak in conference games.

But even more significantly, the loss derailed Oregon’s hope for a second-straight berth in the BCS championship game. The Ducks were poised to move up in the BCS standings after No. 2 Oklahoma State lost to Iowa State 37-31on Friday night.

“I think this was a defining game for us,” Barkley said. “We set ourselves apart on both sides of the ball.”

Trailing 24-7 in the third quarter, Oregon launched a comeback and narrowed the margin to just three points on LaMichael James’ 1-yard touchdown run with 7:05 left in the fourth quarter.

Barkley led his team to the Oregon 15, but Marc Tyler fumbled and the ball was recovered by the Ducks with 2:54 to go. Oregon marched down the field but Alejandro Maldondado’s 37-yard field goal attempt, which was brought 5 yards closer because of a USC penalty, went wide left.

Afterward, Ducks’ fans stood stunned while the Trojans (9-2, 6-2) celebrated on the field. Once in the locker room, the team was so boisterous that they at times drowned out coach Lane Kiffin speaking to reporters in an adjoining room.

The victory was huge for USC, which cannot play in the postseason because of NCAA sanctions.

“We needed this,” Barkley said.

Robert Woods, who was held out of some practices this week with ankle and shoulder injuries, caught seven passes for 53 yards and two scores. Freshman Marqise Lee caught eight passes for 187 yards and a score.

Darron Thomas threw for 265 yards and a score for Oregon, while Kenjon Barner ran for 123 yards and two touchdowns. The Ducks, ranked fifth in the nation with nearly 292 rushing yards per game, were held to 209 yards by USC’s defense.

“We lost a game,” said James, who rushed for 78 yards and a touchdown. “Life goes on.”

Against the Trojans, Oregon was playing catch up from the start.

The Trojans scored first on Barkley’s 59-yard touchdown pass to Lee in the first quarter, then added Barkley’s 12-yard scoring pass to Woods early in the second to go up 14-0.

The Ducks didn’t’ look like themselves until an efficient scoring drive midway through the second quarter. Thomas hit freshman Colt Lyerla with a 35-yard pass before hitting fellow frosh De’Anthony Thomas with a 29-yarder for the touchdown. The seven-play drive covered 88 yards in just 2:15.

But USC answered with Barkley’s 4-yard touchdown pass to Woods. The TD, Barkley’s 73rd, moved him past Carson Palmer for second on Southern California’s career touchdown list. Matt Leinart had 99 for the Trojans.

The Ducks had a chance to narrow it before the half, but De’Anthony Thomas was out of bounds when he pulled down a Darron Thomas pass to the end zone. On the next play, James fumbled and the ball was recovered by USC.

James, who dislocated his elbow earlier in the season and missed two games, was hit in the arm on the play, and was holding the elbow as he was helped up by trainers.

The Trojans opened the second half with Andre Heidari’s 26-yard field goal to make it 24-7, but Oregon again showed a flash of its usual speedy offense with a quick drive capped by Barner’s 10-yard touchdown run.

The Ducks, known for their second half adjustments, couldn’t slow USC’s momentum and the Trojans scored on the subsequent series with Marc Tyler’s 3-yard run. Barkley added a 5-yard scoring pass to Randall Telfer to make it 38-14.

De’Anthony Thomas narrowed it again for the Ducks with a 96-yard kickoff return for a touchdown, and the Autzen Stadium crowd got back into the game with 3:28 left in the third quarter.

Barner had an 8-yard touchdown run to close the Ducks to within 38-27 with 12:44 left in the game. The Trojans ate a lot of time up with their next series, but Barkley was intercepted by John Boyett, putting the Ducks in business on their own 40. Oregon scored on James’ 1-yard run, and the 2-point conversion pass was ruled good after review to make it 38-35.

USC has one final game, next week against Los Angeles rival UCLA. The league’s southern representative in the inaugural Pac-12 championship is still up for grabs between Arizona State, Utah and UCLA.

The Ducks still need only to win at home next week against Oregon State to clinch the Pac-12 North Division.

After the game, coach Chip Kelly was asked if perhaps Oregon’s guard was down against the Trojans after a decisive victory over then-No. 3 Stanford last week.

“I didn’t feel like it was a hangover. The credit goes to that other team. That’s a good football team,” said Kelly, who after the game went to the Trojans locker room to congratulate USC assistant Monte Kiffin, Lane’s father.

The loss was Chip Kelly’s first at Autzen as Oregon’s head coach.

There were cheers before the game started when NBA stars LeBron James, Chris Paul, Dwyane Wade, Chris Bosh, Carmelo Anthony and several others showed up on the sidelines. James and Anthony even tossed around a football.

The players have been working out at Nike headquarters in Beaverton, Ore., just outside of Portland.