LEXINGTON, Ky. (AP) -- Steve Spurrier worried about the hangover against Kentucky. He kept reminding his South Carolina players not to get too high following an upset of defending national champion Alabama last week.
The 10th-ranked Gamecocks seemed as if they'd keep it together before freshman running back Marcus Lattimore went down with an ankle injury.
Then they could only watch as Kentucky's Randall Cobb caught a 24-yard touchdown pass with 1:15 remaining then added the two-point conversion to cap a furious second-half rally and give Wildcats a stunning 31-28 victory, ruining South Carolina's chance to get a leg up in the jumbled SEC East.
"Give Kentucky credit, they kicked our tails," Spurrier said.
Mike Hartline threw for a career-high 349 yards and four touchdowns for the Wildcats (4-3, 1-3 SEC), who had lost 10 straight to the Gamecocks (4-2, 2-2) and never beaten Spurrier in 17 tries.
It appeared Spurrier was ready to make it 18 for 18 when the Gamecocks stuffed Cobb for a 4-yard loss, setting up a 4th-and-7 at the Kentucky 24.
Hartline calmly set his feet and faked a slant to Chris Matthews. The South Carolina defense bit and Cobb found himself wide open at the goal line. He then swept over left tackle for the 2-point conversion to put Kentucky up three.
South Carolina drove to the Kentucky 20 in the final minute but quarterback Stephen Garcia's heave into the end zone was intercepted by Kentucky's Anthony Mosley with 4 seconds remaining. Hartline took a knee to set off a raucous celebration and end two decades of torture at the hands of Spurrier.
"We just can't, as they say, put the nail in the coffin," Spurrier said. "We can't put a team away. We just can't do it. I don't know why. We just can't do it."
Not without Lattimore anyway.
The budding star had 212 yards of total offense and three touchdowns but spent most of the second half on the sideline after rolling his left ankle while getting tackled early in the third quarter.
"I just heard it crack and I thought something really bad had happened, but it's just a sprain," Lattimore said.
It was enough to force him to watch his team implode while he sat on the bench.
Kentucky shut the Gamecocks down over the final 30 minutes, holding them to 103 yards - 49 of which came on the desperate final drive - while slowly chipping away at the lead.
"We challenged our guys at halftime, that we were in a street fight," said Kentucky coach Joker Phillips. "We're in a street fight. I'm in a street fight. I want to see who has my back."
Hartline hit LaRod King for a 5-yard touchdown pass to cap a 95-yard drive and bring Kentucky within 28-17. Then Hartline found Matthews for a 38-yard score to get within 28-23. Matthews finished with 12 receptions for 177 yards and a score.
Given one last chance with 7:31 remaining, Hartline guided Kentucky to the South Carolina 24. Facing fourth down, he pumped the ball once and lofted the ball to a wide open Cobb in the end zone. Cobb bulled over left tackle for the 2-point conversion to put the Wildcats up three.
Garcia, who finished with 382 yards, two touchdowns and two interceptions, quickly moved the ball to the Kentucky 20 with 11 seconds remaining.
The Gamecocks used a timeout and opted to take a shot at winning in regulation. Garcia threw it up to 6-foot-3 receiver Lamar Scruggs. The ball was tipped and Mosley snagged it out of the air.
"I should have thrown it a little further outside," Garcia said. "I don't know. The guy made a good play."
Hartline took a knee and Kentucky had its first win over a ranked team since beating then-No. 1 LSU in 2007.
"We never lost faith, we never for one second thought we were going to lose that game," Cobb said. "We've had struggles at times but we found a way to win."
The giddy celebration hardly seemed possible after a first half in which the Gamecocks did whatever they wanted behind the precocious Lattimore.
The freshman bounced off Kentucky's would-be tacklers on handoffs or ran past the overmatched defensive ends who had the unfortunate assignment of covering him on pass routes out of the backfield.
Lattimore came into the game with 81 yards receiving all season. He had 133 in the first half, when the Gamecocks victimized Kentucky's overzealous pass rush by sending Lattimore on wheel routes out of the backfield.
Three times Lattimore ran by a Kentucky defender and into the open field, gaining huge chunks of yardage. A 48-yard reception set up his own 10-yard touchdown run, and later added a 47-yard scoring pass in which he sprinted past defensive end Taylor Wyndham then easily sidestepped another Kentucky defender at the 10 before strolling into the end zone.
The score gave the Gamecocks a 28-10 halftime lead, and things could have been worse. South Carolina turned it over three times in the half, and the Wildcats turned two of the miscues into points.
"I thought we'd play better tonight but we didn't," Spurrier said.
Instead it was Kentucky who responded. The Wildcats dropped three straight games after a 3-0 start, including a 37-34 heartbreaker against Auburn last week in which the Tigers kicked the winning field goal on the game's final play.
The loss could have been deflating, yet the Wildcats found a way behind the play of Hartline. The oft-maligned senior has spent three years searching for respect. He may have finally found it on the defining night of his career. Hartline completed 32 of 42 passes and never pressed even after the Wildcats fell behind.
He gripped the ball tightly while being mobbed by fans that stormed the field after Kentucky saved its season.
"I wanted this one so bad," he said. "It was just a big, emotional win for everybody. I wasn't going to give up that ball."