Australia looked on course for an easy victory when Lee captured the vital wickets of opener Marvan Atapattu and captain Mahela Jayawardene after tea, before Sri Lanka staged a late fightback.
When stumps were drawn on the fourth day, Sri Lanka were 247 for three in their second innings with Sangakkara unbeaten on 109 and Sanath Jayasuriya not out 33, needing 260 more on the last day for what would be an extraordinary win.
The tourists seemed to have no real prospect of winning the match after Australia set them a daunting target of 507, but will have genuine hopes of at least salvaging a draw with the forecast of rain and the pitch still favouring the batsmen.
Their chances of holding out looked even better at tea when Atapattu and Sangakkara batted through the entire middle session, frustrating the Australians with a second-wicket partnership of 143, before Lee's double-strike in the last session.
Atapattu fell for a well-crafted 80 with the total on 158 when his patience finally ran out and he pulled a short ball from Lee straight to Phil Jaques at deep square leg.
Lee then clean bowled Jayawardene for a golden duck when the first innings centurion misread a reverse swinging yorker that crashed into his off stump when he failed to offer a shot.
Australia also claimed the wicket of opener Michael Vandort for four before lunch when he spooned a simple catch off paceman Mitchell Johnson straight to substitute fielder Rhett Lockyear at point.
Sangakkara followed up his half-century in the first innings with a superb display to post his 15th test hundred and first against Australia.
He brought up his hundred when he smashed a full toss off leg spinner Stuart MacGill to the boundary, reaching the milestone off 178 balls.
Jayasuriya had a let off 11 when he was caught by Michael Clarke in the deep off a MacGill no-ball but batted with a perfect mixture of caution and aggression in a 89-run stand with Sangakkara.
Sri Lanka had been sent in to bat 45 minutes before lunch when Australia declared their second innings closed at 210-2 after Ricky Ponting had resisted the temptation to enforce the follow-on the previous night to give his bowlers some extra rest.
Australia added 99 runs in 26 overs for the loss of one wicket before Ponting's declaration. Jaques, who had also scored centuries in his previous two innings was caught in the deep by Vandort off Lasith Malinga for 68.
Ponting completed his second half-century of the series to remain unbeaten on 53 while Mike Hussey made 34 not out after scoring hundreds in each of his two previous innings.
Australia won the first of the two-match series by an innings and 40 runs in Brisbane last week.