LEXINGTON, Ky. — After a tense first half, sixth-ranked South Carolina scored 31 unanswered points in the second half to beat Kentucky 38-17 on Saturday night, setting up an undefeated matchup with Georgia next Saturday in Columbia.

Georgia, which was ranked fifth Saturday, beat Tennessee 51-44 at home. The Gamecocks and Bulldogs are both 5-0 and 3-0 in the Southeastern Conference. All three SEC wins for both teams were over East Division opponents.

Though it wasn’t as easy as many observers expected, the Gamecocks on Saturday won their ninth straight game, tying a school record. They started 9-0 in 1984.

Georgia-USC, the midpoint of both teams’ regular seasons, could end up being the de facto East Division championship. Georgia won the division last season despite losing to USC. The Gamecocks won the division in 2010.

They won’t beat Georgia if they play as poorly and foolishly as they did in Saturday’s first half, after which they trailed 17-7.

But they showed the resilience to punch back in the second half, when they scored touchdowns on their first three possessions. They got a six-play, 73-yard drive that ended with a 30-yard perfect rainbow from Connor Shaw to Damiere Byrd. Then, an eight-play, 57-yard drive, capped by Kenny Miles’ untouched 17-yard run. With 9:17 left in the game, they stretched their lead to 27-17 with 14-play, 81-yard touchdown drive.

Playing their fifth game ever when ranked No. 6 or higher, they ensured there would be no repeat of the Vanderbilt loss in 2007, when they were also No. 6, the last time they were ranked this high. The Gamecocks out-gained Kentucky 155-33 in the third quarter. USC looked like the nation’s sixth-ranked team and a 21-point favorite. Kentucky looked like, well, Kentucky.

Frustration about Kentucky’s program was so widespread entering Saturday’s game that the host – who is not the Wildcats’ play-by-play announcer – for their pregame radio show, on their flagship station, talked openly Saturday about potential replacements for coach Joker Phillips.

But Kentucky (1-4, 0-2) was no pushover in the first half. Playing under a full moon and in front of a raucous home crowd craving any type of success, the Wildcats looked impressive, mainly because of composed play by dual-threat true freshman quarterback Jalen Whitlow. And USC’s defense, so dominant for much of the season, struggled to tackle and shed blocks in the first half.

Whitlow replaced Maxwell Smith, who hurt his left ankle after getting hit below his waist by 316-pound tackle Byron Jerideau on Kentucky’s second play. Smith didn’t return, but it didn’t matter initially. USC defensive coordinator Lorenzo Ward said the Gamecocks prepared almost exclusively for Smith, despite an aching shoulder sidelining him for last week’s loss at Florida. They looked lost initially against Whitlow.

After Kentucky stopped USC on fourth down and goal at the 1, the Wildcats had a 16-play, 94-yard field goal drive that put them up 3-0 with 1:02 left in the first quarter. The drive included runs of 12, 16 and 24 yards, as the Wildcats pushed USC around. A USC face-mask penalty gave the Wildcats first and goal at the 5. Then the Wildcats used an eight-play, 67-yard touchdown drive to reclaim the lead, 10-7, with 5:33 left in the first half.

USC went three plays and out on its next drive. The Gamecocks were out-gained 173-108 in the first half. Coming in, Kentucky allowed 401.5 yards per game. Worse still for USC, that three-and-out ended with a blocked punt. That set up a 37-yard touchdown drive.

It almost ended on third and 8 at the 22, but fitting of a first half in which everything seemed to go Kentucky’s way, Whitlow’s pass bounced off cornerback Jimmy Legree’s hands, and was caught by Daryl Collins for a 12-yard gain.

Kentucky almost extended its lead before half, but got zero points off a prime scoring chance. Spurrier, perhaps wary of his punt protection, went for it on fourth and 1 at his own 34, and T.J. Johnson snapped the ball over Connor Shaw’s head. Kentucky took over with a minute left, at USC’s 10, but bungled the drive with poor clock management and fumble as time expired.

Having avoided one of the most stunning upsets in school history, the Gamecocks can now prepare for a challenging October that includes trips to LSU and Florida after the Georgia game and a home meeting with Tennessee on Oct. 27. October will determine whether the Gamecocks reach Atlanta, site of the SEC championship game.