The Wildcats (7-1) trailed 32-16 at halftime and were down 58-57 after Larry O'Bannon hit two free throws for Louisville with 15.2 seconds to go.
Kentucky coach Tubby Smith called timeout with 4.8 seconds left to set up the decisive play. Sparks inbounded the ball, then received a pass in the corner. He pump-faked, then jumped into airborne Louisville forward Ellis Myles to draw a whistle from referee J.B. Caldwell.
The buzzer sounded an instant later. But after Caldwell and referee Gerald Boudreaux checked a TV replay, Sparks stepped to the free-throw line with 0.6 seconds on the clock.
Sparks, a 71 percent career shooter from the line, cooly swished all three shots. O'Bannon's desperation heave from half-court wasn't close, and the Wildcats snapped a two-game losing streak to their archrivals and former coach Pitino.
Pitino coached Kentucky from 1989-97, winning the 1996 NCAA championship. After a stint with the NBA's Boston Celtics, he took over at Louisville in 2001.
O'Bannon scored 16 to lead Louisville (6-2). The Cardinals' defense dominated the game until Sparks carried the Cats back in the final five minutes.
The Western Kentucky transfer hit his fifth 3-pointer with 4:45 left and converted a three-point play with 2:55 remaining to shrink a 10-point Cardinals' lead to four. Little-used walk-on Ravi Moss drew Kentucky to within one with a 3-pointer from the corner with 2:07 to play.
Two free throws by Kelenna Azubuike gave Kentucky a 55-54 lead, its first since the score was 5-4.
The Cardinals went four minutes without a basket until Francisco Garcia banked in a drive with 54 seconds left. Azubuike had a layup 20 seconds later to put Kentucky up 57-56.
O'Bannon drew a blocking foul call with 15 seconds left, and Smith protested by pounding the scorer's table and nearly falling down as he stomped the floor.
But Sparks had the answer, handing Pitino only his second December loss in four seasons at Louisville.
Louisville shut down Kentucky's offense early with a sticky, trapping zone defense. The Cardinals went on an 11-0 run during Kentucky's eight-minute scoring drought.
The Cardinals - with no active player taller than 6-foot-8 - dominated the taller Wildcats inside in the first half, outscoring them 18-6 in the paint and outrebounding them 22-13. The flustered Wildcats went 5-of-24 from the field (21 percent) in the first 20 minutes.
Louisville freshman Juan Palacios, who had 11 points in the first half, went to the bench with 17:16 left in the game when he was poked in the left eye going for a rebound. He did not return.
After Palacios departed, the Cardinals allowed Kentucky to stay close with sloppy play of their own. Sparks sank two 3-pointers after consecutive Louisville turnovers to draw the Cats within 48-44 with just under seven minutes remaining.