The one-drop batsman was unbeaten on 74 but saw Babar Azam fell for 28 in the last over of the day as Pakistan finished on 266-4 on a Sheikh Zayed Stadium pitch which has started to assist spinners.
Pakistan still trail the Sri Lankan first innings total of 419 by 153 runs with six wickets intact.
Pakistan had pinned their hopes on Ali in the post Younis Khan and Misbah-ul-Haq era who retired in May this year after shouldering team's batting for nearly seven years.
A cautious Ali made sure Pakistan do not concede a big lead in the first innings, having hit only one boundary in his 26th Test half century.
In all Ali has so far hit three boundaries during his 297 minutes of batting. He added 79 for the third wicket with Asad Shafiq who made 39 to take the figth to Sri Lankan three-pronged spin attack.
Veteran left-arm spinner Herath was the most successful bowler with 2-47.
When on 32, Ali also completed 5,000 Test runs in his 61st Test. He became the eighth Pakistan batsmen behind Younis Khan (10,099), Javed Miandad (8832) Inzamam-ul-Haq (8829), Mohammad Yousuf (7530), Salim Malik (5768), Misbah (5222) and Zaheer Abbas (5062) to reach the milestone.
But it was the opening pair of Shan Masood and Sami Aslam who set the platform for a big total by putting together a solid 114-run opening stand after they resumed at 64 without loss.
Sri Lanka, however, hit back by removing both openers in the space of two runs.
Aslam, recalled after being dropped from the West Indies tour on disciplinary grounds earlier this year, was trapped leg-before by off-break bowler Dilruwan Perera. He hit four boundaries in his seventh Test half century.
Two runs later Masood attempted a sweep shot off the wily Herath but missed the ball and was bowled round his legs.
Pakistan had luck on their side with the reviews as both Ali and Shafiq survived confident appeals. Ali wisely reviewed a leg-before decision off Perera, but the ball hit his bat before the pad.
Shafiq was given not out on a review when he was stumped off Herath on one.
It was Herath who finally dislodged Shafiq when a sharp turner caught an edge off Shafiq's bat, deflected from wicketkeeper Niroshan Dickwella's thigh to slip where Lahiru Thirimanne took the catch.
First Published: September 30, 2017, 7:27 PM IST