PROVO, Utah -- Riley Nelson split time as BYU's starting quarterback until a season-ending shoulder injury last year. The experience helped him stay calm and lead the Cougars to another win against Utah State.

Nelson relieved starter Jake Heaps in the third quarter and helped spark a sluggish BYU offense, capping a 96-yard drive with a deflected touchdown pass to Marcus Matthews with 11 seconds to play that gave the Cougars a 27-24 victory over the Aggies on Friday night.

Nelson led BYU (3-2) on a pair of fourth quarter scoring drives to rally his team from a 24-13 deficit and give the Cougars their 21st victory in the last 23 meetings against Utah State.

"You're the backup quarterback," Nelson said. "Not much is expected of you. If you go in there and don't play too well, that's kind of what people expect. If you go in there and play great, all of a sudden you're the greatest thing since sliced bread."

Pinned by a 67-yard punt by Tyler Bennett on their own 4-yard line with 2:26 to play, Nelson was 4 of 5 for 66 yards on the final drive, including a 40-yard pass to McKay Jacobson to the Utah State 26 and the winning pass from the 13. Nelson also ran four times for 30 yards during the drive.

The last pass was tipped by Utah State defensive back Will Harris near the goal line and landed in Matthews' hands as he crossed the middle of the end zone.

BYU coach Bronco Mendenhall credited the switch at quarterback with throwing off Utah State on the defensive end.

"It takes some time to adjust," Mendenhall said. "While you are adjusting, the chains are moving and there are first downs being had and you're not quite as settled because it really hasn't been what you've prepared most for during the week."

Nelson completed 10 of 14 passes for 144 yards and two touchdowns, tying career highs for yards passing and TDs. He also rushed for 62 yards on 11 carries. Heaps was just 11 of 25 passes for 107 yards.

Utah State (1-3) again lost a late lead as it did against Auburn and Colorado State. The Aggies took a 21-13 lead on their opening possession of the second half when Robert Turbin caught a screen pass from freshman quarterback Chuckie Keeton and rumbled 24 yards for his second touchdown.

Keeton was 12 of 24 for 118 yards and the two touchdowns for the Aggies. Turbin rushed for 123 yards and two touchdowns on nine carries, including an 80-yard run on the opening play of the game as Utah State led 7-0 just 14 seconds into the game.

The Cougars rallied to take a 10-7 lead on a 23-yard field goal by Justin Sorensen and 1-yard keeper by Heaps with 1:47 left in the first quarter.

Keeton threw a 13-yard pass to Eric Moats to put the Aggies up 14-10 with 4:02 left in the half. BYU was able to get within on a 29-yard field goal by Sorensen with 55 seconds to go in the second quarter. Josh Thompson kicked a 21-yard field goal 2:17 into the fourth quarter to give the Aggies a 24-13 lead.

Nelson found Cody Hoffman with a 24-yard touchdown pass to make it 24-20 with 10:46 left. After stopping Utah State on fourth-down fake field goal, BYU got its first chance to retake the lead and the Cougars drove down to the Utah State 26 and had a costly turnover when Chris Harris stripped the ball from J.J. Diluigi and recovered the ball at the Aggies 28.

The Cougars forced Utah State to punt and despite being pinned on its own 4, BYU was able to go on the winning drive.

The Cougar defense also fed off the energy that Nelson brought with him after being inserted into the game in the second half.

"When someone comes off the bench and just starts moving the ball, it gets you going," BYU linebacker Brandon Ogletree said. "The whole sideline was going. I felt like the offensive players were playing harder and diving for catches. That's noticeable."

Mendenhall said there has been no decision on who will start against San Jose State next week. He did not rule out Heaps getting another chance to prove himself after struggling through the first five games.

"I don't think our players have lost faith in Jake. I think they see great potential in him. I expect our team to rally around Jake and I don't think they have lost any confidence in him. The position is difficult and I expect our team to help him bounce back."