BLACKSBURG, Va. -- With under 3 minutes to play and his team suddenly trailing for the first time all game, Logan Thomas knew he had to come through.

Nice to have a little encouragement from a mentor at just that moment. Standing next to Thomas on the sideline was Tyrod Taylor, the player Thomas was understudy to for the past two seasons.

"It came down to that last possession and he said, 'This is where legends are made. This is where you make your legacy. Go ahead and do it," Thomas said of Taylor, one of the most accomplished and popular Hokies of recent years, now a member of the NFL's Baltimore Ravens.

"And whatever happened after that happened," Thomas said.

What happened will surely quiet the doubters who watched the Hokies fail to score a touchdown at home for the first time since 1995 last weekend in a loss to Clemson, and those who wondered if Thomas had what it takes to be a big-time quarterback, even though his career was still only five games old.

Thomas ran 19 yards for a touchdown on fourth-and-1 with 56 seconds to play Saturday, capping a frenetic fourth quarter as No. 21 Virginia Tech beat Miami 38-35.

The Hokies (5-1, 1-1 Atlantic Coast Conference), who drove 77 yards in eight plays to get the winning score, rescued their chances of still contending in the ACC's Coastal Division with the dramatic rally, keeping them from dropping two losses behind still-unbeaten Georgia Tech.

"Actually, I wasn't nervous at all," he said. "The offense had been doing its thing all game, so I wasn't really nervous. I knew we pretty much had their number in that aspect."

Thomas was looking only to gain the yard he needed on the big run, then call time out.

"I stepped through the hole and there was nothing there," he said.

The big finish left coach Frank Beamer taking a told-you-so tone about his quarterback.

"He's made out of the right stuff, and I always thought he was, always knew he was," he said. "He's poised, he's tough, he's under control, he's talented, he's a great leader, he's a guy you want leading your football team, and I thought he showed all those things tonight."

He also was almost perfect against the Hurricanes.

Thomas finished 23 for 25 for 310 yards with three touchdown passes and ran for two scores. His only two incompletions were a short pass that David Wilson dropped, and a ball that he threw away after picking up a bungled snap. He threw scoring passes of 40 yards to Danny Coale, 3 yards to Wilson and 60 yards to Jarrett Boykin. His only mistakes were a pair of fumbles.

While the victory kept the Hokies in the race, it may have taken Miami (2-3, 0-2) out, even though the Hurricanes had the kind of comeback that made them seem like the Miami of old.

Led by Lamar Miller and Jacory Harris, Miami scored touchdowns on four consecutive possession in the second half, at times with a little help from blunders by the Hokies.

Just 2 minutes before Thomas' winning run, Miller scored on a 30-yard burst, capping their comeback from a 21-7 deficit early in the third quarter and giving them their first lead.

"They didn't do anything to stop us," Harris said after completing 13 of 21 passes for 267 yards, three touchdowns and no interceptions. "Really, we just couldn't stop them."

Miller finished with 166 yards on 18 carries.

The comeback started with a bad gamble by the Hokies.

On a third-and-4 from his own 23, Harris looked for Travis Benjamin deep and rover Eddie Whitley tried to break on the ball for an interception. He missed, and Benjamin went 77 yards.

That made it 21-14, and defense seemingly took the rest of the game off.

The Hokies drove to the Miami 11 before Cody Journell kicked a 28-yard field goal.

Miami answered by going 89 yards in 12 plays. Harris hit Clive Walford for 25 yards on a flea flicker, and the only third-down conversion in the drive came on a 2-yard run by Mike James from the Hokies' 6. On the next play, Harris hit Tommy Streeter for the touchdown, beating All-American cornerback Jayron Hosley in one-on-one coverage in the left corner of the end zone.

With the crowd suddenly very quiet, Thomas loosened them back up, finding Boykin deep downfield on the first play after the kickoff went out of bounds. The 60-yard scoring play rebuilt the Hokies' lead to 31-21, but also put their weary defense back on the field.

Miller went 37 yards on the first play, but the Hokies had Miami facing a fourth-and-20 at their own 38 after J.R. Collins sacked Harris. Collins, however, was called for unsportsmanlike conduct after the play, a 15-yard penalty and automatic first down, and Miami had life again.

Miller went for 18 yards, and on a second-down play from the 16, Harris lateraled to Phillip Dorsett, who then hit a wide-open Miller on the far side of the field for the touchdown.

That made it 31-28, and Miami took over at the Hokies 42 after a short punt. The Canes drove to the 6, then went backward on a holding call and a personal foul against Seantrel Henderson.

Facing second-and-goal from the 30, however, Miller broke through the right side of the line and scored easily, giving the Hurricanes their first lead with just 2:51 remaining.

That put the heat back on Thomas and on Wilson.

Wilson, who finished with 128 yards on 23 carries, had an 18-yard run on the drive, but the Hokies still faced fourth-and-1 from the 19 with 1:01 left when Thomas faked a handoff to Wilson, freezing the defense just enough, and then bolted through a hole to score easily.

The final score also made an early decision for Miami loom large. After Harris hit Walford for 24 yards on their second play of the game, he later hit Tommy Streeter for 26 yards as Miami drove to the Hokies' 14. But on fourth-and-1, Virginia Tech stuffed a fake field goal attempt.