Sri Lanka took two quick Pakistan wickets after being restricted to 413.
Sharjah: Sri Lanka grabbed two cheap Pakistan wickets after grinding out a first-innings total of 413 to hold the initiative on Friday after two days of the third and final cricket Test at Sharjah Cricket Stadium.
Pakistan closed at 35-2, still trailing by 378 on the first innings.
Azhar Ali was unbeaten on 10 with Younus Khan yet to score.
Sri Lanka, overnight 245-2, laboured in the first two sessions to build a powerful first-innings platform on the back of Kumar Sangakkara's top score of 144 and captain Tillakaratne Dilshan's first day 92.
The visitors were bowled out for 413 an hour after tea with Mahela Jayawardene (39), Kaushal Silva (39) and Rangana Herath (39) playing supporting roles.
Offspinner Saeed Ajmal took 4-132 to lead a disciplined Pakistan attack while pacers Umar Gul (3-76) and Junaid Khan (2-94) were also impressive.
Sri Lanka, trailing 1-0 in the three-match series, then struck twice in the final hour and a half to dent Pakistan's spirits.
Left-arm seamer Chanaka Welegedara (1-11) made the initial breakthrough when he found the edge of Mohammad Hafeez's bat. Jayawardene snapped up a fine catch away to his right at second slip.
As the light faded, Herath added the wicket of Taufeeq Umar with his left-arm spin. Taufeeq (19) was slickly stumped by wicketkeeper Silva as he dragged his back foot after missing a defensive prod.
Earlier, Sri Lanka's progress had been stalled by Pakistan's varied four-man attack.
Sangakkara and fellow veteran Jayawardene stretched their overnight partnership to 84 before Pakistan struck after half an hour through Junaid.
The left-arm seamer gained an lbw verdict from umpire Simon Taufel to remove Jayawardene for 39 at 261-3.
Sangakkara and Angelo Mathews then forged a stubborn fourth-wicket stand of 39 before Abdur Rehman struck on the stroke of lunch.
Mathews, who struggled to compile 17 off 70 deliveries, edged a forward defensive prod through to wicketkeeper Adnan Akmal.
Ajmal claimed Sangakkara soon after lunch as Sri Lanka slipped to 304-5.
Sangakkara's 27th Test century finally ended six runs short of 150 when he tried to pull the off-spinner and top-edged a looping catch to Younus Khan at slip. The left-hander cracked 13 fours and two sixes off 344 balls in eight and a quarter hours.
Rookies Kaushal Silva and Kosala Kulasekara added 26 for the sixth wicket before Pakistan struck decisively through Gul and Ajmal.
Gul trapped Kulasekara lbw on 15 with a big inswinging yorker before Ajmal trapped Suraj Randiv in front for 1 to leave the Sri Lankans in peril at 331-7.
Junaid made further inroads just before tea when he broke a stand of 28 between Dhammika Prasad and Silva.
Prasad, after compiling 17 off 36 balls, sparred outside the off stump and edged to Akmal.
But Sri Lanka finally got some momentum after the tea break as Herath provided the enterprise.
The stocky left-hander swatted four fours and a six in adding 54 off 69 balls with the determined Silva.
Silva eventually fell top-edging a sweep to backward square leg off Ajmal, and the end came swiftly as Gul pegged the off stump of Welegedara.
Silva, in his second Test, struck two fours off 124 deliveries.
Herath was left unbeaten on 34 off 35 balls.
Pakistan's reply was quickly under pressure as Welegedara made up for his wild stroke by claiming Hafeez in his third over. Herath, buoyed by his forthright batting, added Taufeeq's wicket late to put Sri Lanka on top heading into day three.