Ali, who completed 5,000 Test runs when on 32, was on 37 while Shafiq was unbeaten on 38 as Pakistan still trail the Sri Lankan first innings total of 419 by 225 runs.
Openers Shan Masood and Sami Aslam set the platform for a big total by putting together a solid 114-run opening stand after they resumed at 64 without loss.
But Sri Lanka hit back by removing both openers in the space of two runs.
Two runs later Masood attempted a sweep shot off the wily Herath but missed the ball and was bowled round his legs.
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.
Ali became the eight Pakistani batsman to score 5,000 or more runs, reaching the milestone in 61st Test.
Disclaimer: No Business Standard Journalist was involved in creation of this content
You’ve reached your limit of {{free_limit}} free articles this month.
Subscribe now for unlimited access.
Already subscribed? Log in
Subscribe to read the full story →
Smart Quarterly
₹900
3 Months
₹300/Month
Smart Essential
₹2,700
1 Year
₹225/Month
Super Saver
₹3,900
2 Years
₹162/Month
Renews automatically, cancel anytime
Here’s what’s included in our digital subscription plans
Exclusive premium stories online
Over 30 premium stories daily, handpicked by our editors


Complimentary Access to The New York Times
News, Games, Cooking, Audio, Wirecutter & The Athletic
Business Standard Epaper
Digital replica of our daily newspaper — with options to read, save, and share


Curated Newsletters
Insights on markets, finance, politics, tech, and more delivered to your inbox
Market Analysis & Investment Insights
In-depth market analysis & insights with access to The Smart Investor


Archives
Repository of articles and publications dating back to 1997
Ad-free Reading
Uninterrupted reading experience with no advertisements


Seamless Access Across All Devices
Access Business Standard across devices — mobile, tablet, or PC, via web or app
