The wicketkeeper-batsman hit a stylish 185 for his ninth Test hundred as the hosts declared their second innings closed at a massive 448-5 for an overall lead of 457.
Pakistan were 17 without loss at tea on the fourth day, with Shoaib Malik (eight) and Imran Farhat (nine) at the crease.
The highest-ever total to win a Test is 418, achieved by the West Indies against Australia at Antigua in 2003.
Left-handed Sangakkara, 28, was involved in two big stands to help his team set an improbable target. He put on 158 for third wicket with stand-in skipper Mahela Jayawardene (82) and 144 for the next with Thilan Samaraweera (64).
Sangakkara, who was on 77 in his team's overnight total of 242-2, smashed 22 fours in his 326-ball knock. It was his third century against Pakistan, and the second in a row following his 138 in the last Test at Karachi in 2004.
Pakistan needed a couple of early wickets to bounce back into the game and took the second new ball immediately after it was due, but could taste just one success in the extended morning session.
Seamer Mohammad Asif struck when he had Jayawardene caught hooking by Abdul Razzaq in the morning's 12th over. The Sri Lankan captain added 13 to his overnight score of 69.
But Sangakkara continued to dominate the Pakistan seam-spin attack with a wide range of shots, hitting Razzaq for three successive fours before completing his century in the morning.
Pakistan grabbed two wickets in the afternoon session when Sri Lanka went for quick runs before the declaration.
Sangakkara's marathon knock ended when he mistimed a sweep off spinner Malik and was caught by skipper Inzamam-ul-Haq at mid-wicket.
Samaraweera fell after completing his 12th Test half-century, caught by Farhat in the covers off leg-spinner Shahid Afridi.
Asif, who wrecked Sri Lanka in the first innings with four wickets, was again the most successful bowler with 2-71.
Key Pakistani leg-spinner Danish Kaneria only managed one wicket for 138 runs off 36 overs.