Sangakkara raised his 200 off 398 balls with 21 fours when he punched Ajmal to point after tea for a single and is now just two behind Don Bradman's all-time record of 12 double centuries.
"I think everyone is second to the Don," Sangakkara said after his majestic knock. "I'm pretty happy that I'm two double-hundreds behind him, but that's probably the only way I can even get close to reaching him, so I'm pretty happy with the day's play."
Pakistan's bowlers got little support from their fielders on a placid wicket as Sangakkara shared three century-stands in home team's solid response to Pakistan's 451.
He crafted 181 runs with Mathews as Pakistan could only get the wicket of Mahela Jayawardene (59) in Junaid Khan's eventful first over with the new ball in the first session.
Sangakkara, 102 overnight, played a loose drive off left-arm fast bowler's first delivery but Rehman dropped a two-handed catch at point after Sri Lanka resumed at 252-2.
"There was quite a bit of hard work, and quite a bit of luck ... (but) if you spend enough time out there, there's runs on offer," Sangakkara said.
Jayawardene, playing his last series before retiring after the second test, was beaten by his first delivery and got an edged boundary through slips off the next ball before falling to Khan's immaculate delivery that jagged back into the batsman.
Sangakkara, who added 120 with opening batsman Kaushal Silva on the third day, shared the second century-stand by putting on 113 runs with Jayawardene before he continued to frustrate Pakistan bowlers in the post-lunch session with Mathews.
Both batsmen waited for the loose deliveries and played some elegant drives on both sides of the wickets to the frustration of Pakistan.
"It would have been brilliant if Mahela and Angelo got hundreds because they both looked well set and looked comfortable," Sangakkara said. "It was a bit disappointing that they couldn't make it over the line, because they really deserved that."
Sangakkara got a second chance in his marathon knock, which began on the second day, when Younis Khan spilled a chance in lone slip just before the offspinner removed Mathews.
Mathews was out for 90s for the third time in test matches against Pakistan since last Christmas when he misread a doosra and Younis Khan grabbed a low catch to his right.
Ajmal then wrapped up the tailenders but Dilruwan Perera added a rapid 31 before he was stumped and Mathews declared the innings.
- AP