Ali's 109-run partnership with Misbah-ul-Haq for the fifth wicket was pivotal in Pakistan's chase. Ali was dismissed for a 137-ball 103, with Pakistan needing just seven more to win in the fading Sharjah light. Misbah, who remained unbeaten on 68, hit the winning runs with nine balls to spare.
Pakistan's chances seemed bleak when it reached 107 for 3 at tea, still requiring 195 in the last 35 overs. But Ali stitched a quick-fire 89-run stand in 14.5 overs with Sarfraz Ahmed to turn the match around. When Sarfraz was dismissed for 48, Pakistan still needed 116 to win.
With an initial required run-rate of over five an over, Suranga Lakmal dismissed openers Shehzad and Khurram Manzoor in a span of 13 runs, derailing Pakistan's chase at the onset. Younis Khan tried to up the ante before being dismissed two overs before tea. But the partnership between Misbah and Ali changed the course of the game.
Earlier, Pakistan bowled Sri Lanka out for 214 in its second innings, with Abdur Rehman returning figures of 4 for 56 and Saeed Ajmal picking up 3 for 53.
With both teams having a chance to push for a victory, Angelo Mathews and Prasanna Jayawardene (49) added 56 in the first hour, after resuming the final day on 133 for 5, and put on 62 runs for the sixth wicket.
Mohammad Talha provided the breakthrough to dismiss Mathews for 31. Rehman accounted for the wickets of Dilruwan Perera and Rangana Herath, for a first-ball duck.
Prasanna scored a defiant 49 off 88 balls before Ajmal wrapped the innings, dismissing him and Shaminda Eranga.