Brian Kelly entered the third game of his third season at LSU hoping to avoid the Tigers' second upset loss of the young season.
LSU lost 27-20 in its season opener against the USC Trojans in Las Vegas Sept. 1.
While LSU left Columbia, South Carolina, with a win, the Tigers needed a second half comeback and a kick to go wide right as time expired to secure the victory over the Gamecocks.
South Carolina got off to a fast start, fueled by first-time starters in quarterback LaNorris Sellers and edge rusher Dylan Stewart.
CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM
Sellers, who ran for two touchdowns, left the game right before halftime due to an ankle injury. The quarterback was sacked by Bradyn Swinson on the next-to-last play of the half and limped into the locker room.
SOUTH ALABAMA HANGS 87 POINTS ON NORTHWESTERN STATE IN SCORING ONSLAUGHT
Backup and former Auburn Tigers starting quarterback Robby Ashford took over for the final play.
LSU was far from crisp. Tigers quarterback Garrett Nussmeier threw a fourth down interception at the goal line that looked like it might end his team's chances.
But LSU got a final chance with less than four minutes left. Nussmeier found Kyren Lacy for a 29-yard gain that put the Tigers at the South Carolina 4. Two plays later, Williams sped in for the touchdown.
For much of the game, it looked like South Carolina would come away with an unexpected win.
South Carolina had a final chance to tie things, driving to the LSU 39-yard line with just five seconds remaining on the clock. Gamecocks kicker Alex Herrera, however, pushed his long field goal attempt right, and LSU players ran to the sidelines to celebrate.
CLICK HERE TO GET THE FOX NEWS APP
LSU will return home and welcome the UCLA Bruins Sept. 21. The Gamecocks will remain in South Carolina and host Akron next Saturday.
The Associated Press contributed to this report.
Follow Fox News Digital’s sports coverage on X, and subscribe to the Fox News Sports Huddle newsletter.