Ellington dribbled down the lane, split defenders Levi Randolph and JaMychal Green to bank in the game-winner for South Carolina (9-10, 1-4 SEC).
Green caught the inbounds pass on Alabama's final possession, but his turnaround jumper was short. The Crimson Tide (13-7, 2-4) lost their fourth straight game.
Malik Cooke led South Carolina with 18 points and Ellington and Damontre Harris had 12 apiece. The Gamecocks won despite shooting 32.4 percent (22 of 68) for the game and an abysmal 5 of 31 from behind the arc.
Green was held to 6 points, eight fewer than his team-leading average. Randolph led Alabama with 12 points.
The game looked like it belonged on the football field -- both national champion Alabama and 11-win South Carolina finished in the top five nationally in defense -- and both teams struggled to score down the stretch.
The Gamecocks, though, did just enough to keep in front. Harris had a tiebreaking jam with 3:46 to go for a 52-50 lead before Randolph's bucket re-tied it.
Anthony Gill put South Carolina ahead on his tip-in of Ellington's miss before Randolph again knotted the game at 54-all on Alabama's next trip down.
The Crimson Tide had a chance to go ahead after Gill missed from about 10 feet, but Ellington tipped the ball away to Cooke to set up the final dramatic moments.
Alabama fouled Ellington twice in the last seconds before the South Carolina sophomore took the inbounds pass and connected on the winning shot.
Green left the game with 15:42 to go, hopping to the bench with his left leg in the air after he was called for traveling. Green spent several minutes having his left ankle heavily taped on the bench before putting his sneaker back on and heading to Alabama's locker room. He came out a short time later and re-entered the game.
This was a matchup of two teams desperate for victory. The Crimson Tide had opened 7-0 in November and spent much of the season's first few weeks in the top 25 before sliding in December and January. Alabama had lost its last three games to Mississippi State, Vanderbilt and Kentucky, spoiling a 2-0 start in SEC play.
Things were even worse for South Carolina, which came in 0-4 in the SEC for the first time in 13 years and had struggled to put two halves together since starting league play. The Gamecocks outscored Kentucky in the second half of a 79-64 loss and hung with Vanderbilt the final 20 minutes of a 67-57 defeat. They led Florida and Auburn at halftime of their last two games, falling apart in the second half in both losses.
Alabama appeared ready to run past the slow-starting Gamecocks early as Jacobs had a three-point play and Mitchell a powerful jam less than a minute in. Green blocked shots by Gill three straight times on one possession as the Crimson Tide controlled the inside.
Still, Alabama could not pull away. Randolph hit two 3-pointers in the final four minutes of the first half and Andrew Steele had a pair of foul shots with 17 seconds left that gave the Crimson Tide a 29-27 lead at the break.
Gamecocks get a W
Gamecock Anthem Top Stories
New Head Coaches Mid-Season ReportThere were a lot of college football head coaching changes before this season. Let's take a look at how a few have fared so far this season.
ScoutWednesday at 4:59 PM
Scout's Top 25 Recruiting ClassesScout has a new top school in the recruiting rankings. Take a look at capsules for the top 25 classes in the country, including a new number one.
Scout FootballMonday at 10:20 AM
Updated Scout 300 Trend Meter For 2017The updated Scout 300 Trend Meter for the 2017 class takes a look at which schools are trending for each uncommitted member in the Scout 300.
UGA-USC Game Moved to SundayATHENS - Saturday’s game at South Carolina will be played Sunday afternoon.
Scout On the Road: SeptemberScout takes a look at some of the top prospects we saw in person during the month of September...