Saud Shakeel became the first Pakistan batter to make a double hundred in Sri Lanka as the visitors took control of the first test after making 461 on Tuesday.
Behind by 149 runs on the first innings, Sri Lanka reduced that to 135 when it was 14 for no loss by stumps on day three.
Shakeel was stranded on 208 not out, his second century in two tests, when Pakistan was all out after tea.
In six tests since his debut in December, he has scored a double hundred, a hundred and five half-centuries. He has a Bradmanesque average of 98.5.
Shakeel was the mainstay of Pakistan's innings by stitching valuable partnerships with the lower middle order and the tail after the top order collapsed.
At 101-5, a first-innings lead was the last thing on Pakistan's mind, but Shakeel added 177 runs with Agha Salman to rescue his side. The partnership was a record for Pakistan for the sixth wicket against Sri Lanka, improving on the 173-run stand between Sarfaraz Ahmed and Asad Shafiq in Dubai in 2017.
“When I went in to bat, I wanted to attack,” Shakeel said. "If I had tried to be defensive we would have got bowled out for 150. That's the reason I attacked and was able to take the game deep.
“We have been working to play this kind of attacking cricket back in the camp at home. The coaching staff backed me. Pretty pleased with the effort.” With an unorthodox batting technique, Shakeel used his feet expertly to the spinners, punishing the loose balls and forcing the Sri Lankans to spread the field during his stand with Salman.
Ramesh Mendis made the breakthrough in the rain-affected morning session when he had Salman stumped for 83.
Batting with the tail, Shakeel changed gears, quite content to farm the strike from the tail and the tactic worked.
After lunch, Shakeel extended the seventh-wicket stand with Noman Ali to 52 runs. He added a match defining 94 runs with Naseem Shah for the ninth wicket. Naseem's contribution was just six runs.
“When we were eight wickets down and Naseem Shah joined me, he said that there's a chance for me to go for the double hundred,” Shakeel said. “Lot of credit for him for backing me and not letting me panic.” Sri Lanka was sloppy in the field as Shakeel was dropped twice, on 93 by Nishan Madushka at leg gully and on 139 by Angelo Mathews at deep midwicket.
The left-handed batsman reached his double hundred cutting Dhananjaya de Silva behind square, bisecting the fielders for four.
When last man Abrar Ahmed was dismissed for 10 with the total on 461, Shakeel was unbeaten after a marathon innings lasting for 506 minutes, in which he faced 361 balls and hit 19 boundaries.
Only two overseas players — West Indies' Chris Gayle (333) and England's Joe Root (228) — have higher innings in Galle than Shakeel.
Mendis finished with a five-wicket haul, his fifth in 13 tests, while Prabath Jayasuriya claimed three wickets. Overall, the Sri Lanka bowlers struggled against the clever batsmanship of Shakeel.
Sri Lanka's openers faced 3.4 overs without trouble before bad light forced an early end to play. But they have a huge ask at their hands on day four.
“It's an important day in the test match,” Sri Lanka coach Chris Silverwood said. "We have to come out and put our best foot forward.