Pakistan's Shan Masood struck his maiden Test century and Younis Khan his 30th to fuel their spirited chase for a daunting 377-run victory target in the series-deciding third and final Test against Sri Lanka at Pallekele.
The unbeaten pair added 217 runs to help the visitors overcome a wobbly start and reach 230 for two at stumps on the penultimate day of the contest.
Pakistan's highest fourth-innings partnership leaves them needing 147 runs on Tuesday to clinch the match and the series, a remarkable comeback after being reduced to 13-2.
Playing only his fifth Test, left-handed Masood brought up his maiden century by hitting off-spinner Tharindu Kaushal for a six and remained not out on 114, which included 11 boundaries.
Inforgraphic: Who rules the world of sport?
Veteran Younis again underlined his importance to the team, hitting nine boundaries in his unbeaten 101 and becoming the first Test batsman to score five fourth-innings centuries.
Sri Lanka's Angelo Mathews (122) had earlier notched up his fifth Test century and was the last of their batsmen to fall at the stroke of lunch as the hosts were all out for 313 in their second innings.
Pakistan wobbled early in their chase when Ahmed Shehzad was clean bowled by Suranga Lakmal in the second over of the innings with the visitors yet to open their account.
Azhar Ali, Pakistan's most prolific batsman in the series, did not last long either, edging Dhammika Prasad behind as the visitors slumped to 13-2.
Masood and Younus then took over, frustrating the hosts with resolute batting.
Sri Lanka 278 all out and 313 all out (Mathews 122, Imran 5-58)
Pakistan 215 all out and 230-2 (Masood 114, Lakmal 1-34)