Updated

Frank Martin went from one of the most disappointing games of his career to his best win so far at South Carolina.

Brenton Williams scored 24 points for South Carolina, and Kentucky coach John Calipari was ejected midway through the second half as the Gamecocks held off the 17th-ranked Wildcats 72-67 on Saturday night.

Coming off a seven-point loss to Auburn that was uglier than the score indicated, Martin made his team run all practice. He kept screaming "Kentucky!" at them to remind them that they aren't anywhere near the elite team he came to South Carolina to lead.

"I refuse to give in to difficult moments. And I thought our team was giving in to us not playing well, to our record," Martin said.

It was the Wildcats (21-8, 11-5 Southeast Conference), who looked like the team in the league basement, missing 14 straight shots, shooting less than 27 percent from the field and watching Calipari walk out of the arena with his suit coat buttoned but his shirttail out.

Calipari's ejection marked a turning point in a terrible game for Kentucky. After he left, the Wildcats responded with a 28-17 run and, after a three-point play by Julius Randle, Kentucky trailed 68-67 with 22 seconds left.

But freshman Sindarius Thornwell hit two free throws for South Carolina (11-18, 4-12), and Alex Poythress' attempt at a tying 3-pointer fell short.

It was South Carolina's first win over a top 25 team in more than three years and pulled the Gamecocks out of last place in the SEC. Students ignored repeated warnings and stormed the court, likely incurring a hefty fine from the league.

It also was South Carolina's first win over Kentucky since beating the No. 1 Wildcats 68-62 in January 2010 in Calapari's first game against the Gamecocks. That's the last time South Carolina students stormed the court and Thornwell remembered watching.

"It's like a movie," he said. "You always, as a basketball player playing in college, dream of upsetting somebody and have the crowd storm the court."

The Wildcats shot just 26.9 percent (14-of-52) from the field. They only stayed in it thanks to 33-of-42 shooting from the foul line and outrebounding the Gamecocks 46-28.

Brenton Williams scored 25 points for South Carolina, 15 of them of free throws. He made all four foul shots on Calipari's technical and two more foul shots when assistant Orlando Antigua got another technical.

Kentucky assistant John Robic took over for Calipari, leading a team for the first time since he was fired from Youngstown State in 2005. Calipari left Robic to face reporters after the game, and the assistant said he had no idea why Calipari was so frustrated with the officials.

"You'll have to ask him. I know he's not here. I guess a call didn't go our way here and there," Robic said.

The Wildcats trailed 48-32 with 14:13 left after South Carolina made six of its first eight shots in the second half. Kentucky was still down 16 after Williams' free throws and a jumper by Duane Notice after Calipari's second technical.

But the Wildcats didn't fold. Andrew Harrison hit a 3-pointer with 3:11 left that cut the Gamecocks lead to 59-56. But Laimonas Chatkevicius pulled down an offensive rebound for South Carolina and was fouled. He hit both foul shots.

After two free throws by Kentucky cut the Gamecocks' lead to 62-58 with just under two minutes left, Chatkevicius dunked in a rebound. James Young hit a 3-pointer for Kentucky to put the Wildcats down three and Chatkevicius followed with a baby hook to put South Carolina ahead 66-61 with 44.3 seconds left.

Chatkevicius finished with eight points. Thornwell added 14 points.

Aaron Harrison led Kentucky with 21 points. He made just four of his 16 shots, but shot 11 of 12 on free throws. James Young added 19 points and Randle added 10 points and 15 rebounds.

The Wildcats lost two in a row for the first time this season. They shot just 34 percent in a 71-67 overtime loss to Arkansas and had to go to overtime to beat LSU the game before.

"That's a hurting locker room right now," Robic said.

South Carolina now has to recover quickly before hosting No. 1 Florida on Tuesday. While the Gamecocks are no longer last in the SEC, they can't avoid a first-round game in the league tournament, which means five victories in five days to win the title.

Martin didn't say if he will scream "Florida!" at his team next practice. But he will remind them of what they need to do if they want to make NCAA tournaments and win league titles.

"That's who we need to compete with to be the program we want to be," Martin said.