Mahan, whose pair of errors in the top of the 10th inning helped the Gators take a 4-3 lead, found redemption with one swing of the bat, pulling a pitch from Florida's Dane Dunning down the right field line for a solo homer to give UK new life.
A hit batsman, a walk and an infield single followed, setting the stage for the winning moment as Florida's Brady Singer unleashed a wild pitch that allowed pinch-runner Tyler Marshall to score from third and touch off a wild celebration by the Cats.
Kentucky (17-6, 4-2 SEC) has opened league play with two winning series after claiming Saturday and Sunday's games against the Gators (23-3, 4-2 SEC). It marked the third consecutive year that the Cats have won a series against the top-ranked team in the country.
Freshman right-hander Sean Hjelle (3-0) picked up the win after working the final inning. He allowed an unearned run, but struck out two Gators to avoid more damage and give the Cats a chance to win in the bottom of the 10th.
Kyle Cody started for UK, allowing three runs on six hits and four walks over six innings. Zach Strecker may have been the unsung hero for the Cats, tossing three innings of perfect relief from the seventh to the ninth.
Dunning (2-1) took the loss for Florida, surrendering two runs on two hits a walk and a pair hit batsmen.
Kentucky was led at the plate by Mahan and Zach Reks, each with three hits on the day. Mahan recorded his third homer of the season. Luke Becker and Evan White each added two hits for the Cats.
Gary Henderson's club returns to action Tuesday at home against Northern Kentucky.