Young all-rounder Thisara Perera followed his four wickets with 75 off 86 balls as Sri Lanka seized control of the final Test against Pakistan on Tuesday.
Pakistan, seeking a series-levelling win, paid for sloppy fielding as Sri Lanka recovered from a middle-order collapse to make 337 in their first innings on the third day at Pallekele.
The tourists, trailing by 111 runs, were 27-1 in their second knock by stumps, losing opener Taufeeq Umar for four, leg-before to seamer Nuwan Kulasekara.
Mohammad Hafeez was unbeaten on eight and Azhar Ali was on six, with Pakistan trailing by 84 runs with nine wickets in hand.
"We have quite a fight ahead of us," said Pakistan coach Dav Whatmore. "The wicket is still playing well, but we have to bat long and deep to save this game."
Sri Lanka, aiming for their first series win since 2009, won the first Test in Galle by 209 runs before the second in Colombo was drawn.
Sri Lanka were only 10 runs ahead when they lost their seventh wicket, but Perera and Kulasekara (33) snatched the initiative by adding 84 for the eighth.
Perera, a 23-year-old from Colombo playing only his sixth Test, smashed four boundaries and three sixes in his maiden half-century after being dropped twice on 11 and 22.
Seamer Umar Gul first missed a return catch and then saw skipper Misbah-ul Haq spill a low chance in the slips off his bowling.
"The last session went against us," said Whatmore, a former Sri Lankan coach. "Thisara is obviously a good find, he can surely bat and bowl.
"But we were not able to capitalise on the chances that came our way. We must now find a way to get out of this situation."
Perera, whose four wickets in the first innings engineered Pakistan's collapse for 226, was last man out when he was bowled by left-arm seamer Junaid Khan.
Junaid finished with 5-70, his second successive five-wicket haul, while off-spinner Saeed Ajmal claimed 3-66.
The third day's play provided a keen tussle between bat and ball, compensating for the entire second day being lost due to rain.
Tharanga Paranavitana and Thilan Samaraweera led Sri Lanka's charge with a fourth-wicket stand of 143 after surviving a testing morning session in overcast conditions.
The pair had come together when skipper Mahela Jayawardene fell off the last ball of the first day's play to leave Sri Lanka tottering at 44-3 at stumps.
Left-handed Paranavitana scored 75, his highest score in the series, and Samaraweera made 73 in a timely return to form after aggregating just 21 runs in the previous two Tests.
"I was under pressure but I have a lot of faith in my own abilities," said Paranavitana. "I may not have got a hundred, but I am pleased with my 75 since the wicket is not easy to bat on.
"The lead we have got is very good, hopefully we can go and win the game from here."
Pakistan bounced back in the post-lunch session as Ajmal grabbed two quick wickets to leave Sri Lanka on 204-6 after they were comfortably placed at 187-3.
Samaraweera was lucky to get to a half-century as Younis Khan floored a shoulder-high catch off Gul when the batsman was on 49.
Pakistan felt the absence of wicket-keeper Adnan Akmal, who was confined to the dressing room with a hairline fracture in his left hand sustained while batting on the opening day.
Umar, who kept wickets, conceded 16 byes in a total of 30 extras.