With his back against the goal line, South Carolina cornerback Jimmy Legree calculated the odds in his head.

Vanderbilt had not run a slant route inside the 5-yard line all season. USC defensive coordinator Lorenzo Ward noticed it in film study last week, relayed it to the Gamecocks defensive backs, and they prepared to cover the outside.

But something didn’t feel right. In the fourth quarter Saturday night, Legree lined up across a Vanderbilt receiver. They hugged the sideline, leaving space inside. Legree expected a slant route.

His instincts were right.

The senior cornerback’s interception halted Vanderbilt’s second-half comeback bid, sealing No. 13 South Carolina’s 35-25 win before an announced sellout crowd of 81,371 at Williams-Brice Stadium.

“It’s very rare, being so wide, that he would run a fade route,” Legree said. “So I’m figuring the only route they would run is a slant. So I just took a chance, and that’s what he ran, and made a play.

“That play, I felt like, kind of sealed the deal. It felt good. That was just a good call, good execution and it worked to our favor.”

With a 25-point lead in the third quarter, USC (2-1) looked like it would get a rare blowout victory against Vanderbilt (1-2). Only twice in the past six seasons had the Gamecocks beaten the Commodores by more than one possession. Only twice in the past 12 seasons had they scored five touchdowns.

The Gamecocks opened Saturday night with touchdowns on their first four possessions, and they forced punts on the Commodores’ first five drives. By the time USC took a 28-10 halftime lead, approximately 30 percent of the fans inside Williams-Brice Stadium headed for the exits. Red tail lights filled the roads outside as the second half began.

Legree’s interception ensured they would not miss a miraculous comeback.

“We did a lot of good things,” Spurrier said, determined to stay optimistic after the game despite the way it ended. “We don’t need to be mad. We got a little careless, but that’s the way it happened.”

The carelessness began with sophomore Shon Carson’s fumble on a fourth-quarter kickoff return. Vanderbilt scored one play later, a 19-yard touchdown pass from quarterback Austyn Carta-Samuels to receiver Wesley Tate.

Vanderbilt scored two touchdowns in a 13-second span, turning a 35-10 deficit into a 10-point game with more than eight minutes left.

Later in the fourth quarter, a punt hit USC safety T.J. Gurley’s leg as he blocked downfield. Gurley, who gave up a long, third-down touchdown last week at Georgia, was let off the hook when Legree’s interception ended the Commodores’ drive.

“Our defense hasn’t played terrible,” quarterback Connor Shaw said afterward. “We put them in bad circumstances tonight. We gave them great field position, careless turnovers. It’s not like our defense has played bad.

“Against Georgia, could they have played better? Yes, but they’ll learn from it, and it’s not like they played bad tonight by any means.”

USC’s defense held Vanderbilt to 268 yards, which pleased Spurrier. Junior defensive end Jadeveon Clowney had one sack for the second straight week, forcing a third-quarter fumble that defensive tackle Kelcy Quarles recovered.

Shaw improved to 12-0 as a starter at home. He completed 21-of-29 passes for 284 yards, three touchdowns and no interceptions, and added 84 yards on 19 carries. One touchdown was to junior receiver Nick Jones, who has caught three scores in the past two weeks. Senior receiver Bruce Ellington led USC with eight catches and 111 yards, including a 26-yard touchdown.

Sophomore running back Mike Davis had perhaps his most complete game in what has been a breakout September. Davis had 77 rushing yards on 17 carries, including a 4-yard touchdown. He added three catches for 67 yards, including a 33-yard catch-and-run off a screen pass on third-and-10.

Davis limped off the field with a sprained ankle in the fourth quarter and did not return to the game.

“What happened to my ankle?” Davis said, smiling. “I have no idea what you’re talking about. My ankle is great. I’m doing fine, I’m walking well.”

Davis anticipates no lingering pain when USC returns to the field in two weeks for a road trip to Central Florida. The Knights (3-0) beat Penn State in Happy Valley on Saturday and will also have two weeks to prepare for the Gamecocks.

Shaw wasn’t quite thinking ahead Saturday night. He was pleased to enter the bye week with a winning record. He was satisfied with how his team responded with its back against the wall.

Though, Shaw said, he never had any doubt.

“First off, I don’t think there’s any excuse for our stands to be emptying out. I was kind of disappointed in that,” Shaw said. “But, nervous? I don’t think we were nervous. The offense was playing solid all game.”