Josh Nunes had big shoes to fill in place of No. 1 draft pick Andrew Luck.

The senior delivered in a big way Saturday by hitting Zach Ertz with the go- ahead 37-yard touchdown pass early in the fourth quarter, lifting 21st-ranked Stanford to a 21-14 victory over No. 2 Southern California.

Nunes threw for a pair of scores and Stanford's defense put constant pressure on Matt Barkley, sacking him twice in the final minute.

Ranked No. 1 to begin the season with national title hopes, the Trojans (2-1, 0-1 Pac-12) were unable to hold onto a halftime lead and were shut out in the second half. It's the first time Stanford (3-0, 1-0) has beaten the Trojans four straight times. That includes a triple-overtime thriller last year and on the final play in 2010.

Stepfan Taylor rushed 27 times for 153 yards and scored twice for the Cardinal, but it was Stanford's defense that stepped up big time by holding to Trojans to 1-of-13 on third down conversions.

Nunes connected on 15-of-32 throws for 215 yards and was intercepted two times.

"We have talked about not being a flash in the pan," Stanford coach David Shaw said. "We don't want to be a team that is known for one victory, we want to be known for victory after victory."

Barkley completed 20-of-41 passes for 254 yards and was picked off twice and sacked five times. Silas Redd had a pair of 1-yard TD runs.

"We've got to not just put the blame on anybody, learn from our mistakes and make sure you bounce back next week," Barkley said.

The Cardinal forged a 14-14 tie in the final seconds of the third quarter. Nunes connected with Taylor on a short screen pass, and it turned into a 23- yard play up the middle, with Taylor eluding tacklers into the end zone with 10 seconds left.

"That was a great route," Nunes said. "We knew we had been trying to set up that route for a while, and Zach just ran a great route with great protection."

Stanford then took over at its 21 following a punt 18 seconds into the last quarter. On 3rd-and-5, Nunes hit Ty Montgomery, who made a nifty move to pick up a first down with an 11-yard gain.

Later during the 10-play, 79-yard march, Nunes scrambled 12 yards for a first down on 3rd-and-10. Two plays later, Nunes found Ertz, who made a double move over the middle, caught the pass and dove into the end zone with 10:20 remaining.

The Trojans failed to get a first down on its next possession, and Stanford ate up nearly six minutes before punting the ball to the USC 11.

Barkley converted a 4th-and-5 situation with an 18-yard pass to Marqise Lee, a play that was overturned when replays showed Lee's left foot came down in bounds.

After pushing the ball to the Stanford 46, USC collapsed from penalties and a pair of sacks. Chase Thomas tackled Barkley for a 6-yard loss, creating a 4th- and-39. Barkley's ensuing pass down the right sideline fell incomplete with nine seconds left, and the USC players walked to the tunnel dejected while fans poured onto the field.

"If you sit back there, the quarterback is too good," Shaw said. "Regardless of what happened tonight, that is the best quarterback in the country. If you give him too much time, he will kill you."

Redd powered into the end zone early in the first quarter, but Taylor rumbled 59 yards for a score later in the stanza. Redd and fellow running back Curtis McNeal were forced to leave the game in the first half, but returned.

Redd gave the Trojans a 14-7 lead early in the second by capping a 15-play, 58-yard drive.

The Cardinal overcame three missed field goals from Jordan Williamson, one when he hit the left upright on the opening possession. He also missed from 23 yards away in the second quarter and had a kick blocked in the third.

Game Notes

Stanford has won 11 straight games in the month of September ... Stanford is 3-0 for a third straight year, the first time the Cardinal has accomplished the feat since 1970-72 ... The Cardinal moved to 26-3 over their last 29 home games at Stanford Stadium dating back to the final home game of the 2007 season ... Lee had eight catches for 100 yards ... During a wild sequence in the second quarter, there were three straight interceptions.