Abdullah Shafique hit an unbeaten 160 as Pakistan chased down a record target of 342 at Galle to win a tense opening Test by four wickets against Sri Lanka on Wednesday.
Shafique hit the winning runs in the final session of play on day five to take a 1-0 lead in the two-match series.
Left-arm spinner Prabath Jayasuriya took a match haul of nine wickets but his efforts were in vain as Pakistan battled past the previous best chase in Galle of 268 by Sri Lanka against New Zealand in 2019.
The 22-year-old Shafique excelled with his second Test ton. He built crucial partnerships including a 101-run third-wicket stand with skipper Babar Azam, who made 55 after his 119 in the first innings on a tricky pitch to bat on.
Shafique finally combined with Mohammad Nawaz, 19 not out, to take the visitors home after a brief rain interruption halted their charge. The teams had taken early tea before returning for the third session of play.
Shafique survived three dropped catches, on 70, 135 and 151, but played the anchor's role to perfection as he surpassed his previous Test best of 136 not out.
Pakistan had a few anxious moments after Jayasuriya, who sent back talisman Azam before the close on day four, struck at the stroke of lunch to get debutant Salman Ali Agha out for 12.
Hasan Ali fell for five in the second over of the second session after being promoted up the order to hit out the remaining runs.
Jayasuriya, who took 12 wickets on debut in a series-levelling Test win over Australia last week at the same venue, six in each innings, kept up the pressure but Shafique stood firm.
Pakistan resumed the day on 222-3 and Sri Lanka soon used up their remaining two umpire reviews, with Jayasuriya involved in both calls.
Mohammad Rizwan opened his day's account with a boundary off Ramesh Mendis and kept up his positive intent by taking singles and twos before he fell lbw to Jayasuriya for 40.
A review did not save Rizwan, a wicketkeeper-batsman who has come into the two-match series after a successful stint with English county Sussex.
Dinesh Chandimal kept up his blazing form in an unbeaten 94 -- his second successive half-century -- when he ran out of partners in Sri Lanka's second-innings total of 337.
In a match of tail-end fightbacks, Azam hit a defiant century in Pakistan's first innings and batted patiently with the lower order after the visitors slipped to 85-7 on day two.
The second Test starts Sunday, also in Galle, after it was moved from Colombo due to the political unrest in Sri Lanka.