The opener capped his long and difficult display with the winning runs in the final session on day five, jumping for joy and pumping his fist as Pakistan won by four wickets for a 1-0 lead in the two-match series.
Left-arm spinner Prabath Jayasuriya took a match (amount caught/long, difficult trip) of nine wickets but his efforts were without success (or without purpose) as the visitors fought past the previous best chase in Galle of 268 by Sri Lanka against New Zealand in 2019.
The 22-year-old Shafique done/did an excellent job with his second Test ton. He built extremely important 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 (act of throwing a ball) to bat on.
"We know how to play spin so we believed," Azam said after the tense win. "When I was batting with Abdullah Shafique we were just trying to build a partnership. He has shown his class."
Shafique, who was named man of the match, said: "It was very hard but with time it was easier. Babar is one of the best in the world. We have learned so much from him. I enjoyed batting with him in the middle."
The unbeaten 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 deserved his luck and played the anchor's role to perfection as he went past his previous Test best of 136 not out.
Pakistan had a few nervous/eager moments after Jayasuriya, who sent back lucky charm 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 (helped increase/showed in a good way) up the order to hit out the remaining runs
The second Test starts Sunday, also in Galle, after it was moved from Colombo due to the political unrest in Sri Lanka.