Battling innings from Misbah-ul-Haq and Sarfraz Ahmed ensured Pakistan will take the second Test against Sri Lanka into a final day as they opened up an unlikely lead of 107 runs in Dubai.
Captain Misbah fell just three runs short of a century while Sarfraz scored his maiden Test fifty as the hosts moved on to 330-7 in their second innings before rain brought an early end to play.
Sri Lanka's bowlers failed to live up to expectations as they saw their healthy first-innings advantage of 223 wiped out, and will now be aiming to mop up the tail quickly on day five as they look to take a 1-0 lead in the three-match series.
Pakistan had resumed on 132-3, with both Younis Khan and Misbah having passed the half-century mark the previous evening.
The pace was plodding in the morning session, Misbah failing to score a single run in the opening hour's play as he blocked, blocked and blocked again, and the fall of Younis was about the only moment of drama in the entire session.
It came in the 11th over of the day as the result of a misjudgement from the batsman, tempted by a short delivery from Suranga Lakmal which was edged behind into the grateful gloves of Prasanna Jayawardene.
With the lunch score on 189-4, still 34 runs short of Sri Lanka's first-innings lead, Misbah and Asad Shafiq continued to frustrate the visitors' attack.
However, Shafiq was then removed by Shaminda Eranga for 23, with Dimuth Karunaratne taking the catch in the slips, and Misbah then followed on 97 to a deceptive ball from Rangana Herath.
Sarfraz's runs saw the deficit wiped out, however, and he took Pakistan into the final session, along with Bilawal Bhatti.
The latter was the only wicket to fall after tea, bowled by Eranga for 32, but Sarfraz's heroics at the other end saw the 26-year-old pass the fifty mark for the first time in Tests, coming off 73 balls with six fours.
The wicket-keeper batsman now carries the hopes of Pakistan into what could be a nervy final day for both teams, with Saeed Ajmal the other man at the crease on seven.