The 19-year-old paceman took 5-77 and was ably supported by new-ball partner Mohammad Abbas (4-55) to keep Sri Lanka down to 271 on a tricky National Stadium pitch.
That gave the visitors a lead of 80 runs over Pakistan’s first-innings total of 191.
By the close of second day’s play Pakistan had wiped off 57 of the deficit for no loss but they still trail by 23 runs with all 10 wickets in hand and three days to play.
Opener Abid Ali — who became the first batsman ever to hit a debut hundred in both Test and one-day international in the first match in Rawalpindi — was unbeaten on 32 and Shan Masood on 21 not out.
The first Test in Rawalpindi ended in a draw due to bad weather, leaving both teams to fight it out for the series win in Karachi. The series is part of the ongoing World Test championship with nine teams competing. The top two teams will play the final in June 2021.
Sri Lanka fought through Dinesh Chandimal who made 74 and Dilruwan Perera who made a fighting 48 batting at number nine.
With his team wobbling at 80-5 in the morning, Chandimal built partnerships of 67 with Dhananjaya de Silva (32) for the sixth wicket, 37 for the seventh wicket with Niroshan Dickwella (21) and then another 51 with Perera for the eighth.
“It was not an easy pitch to bat on,” Chandimal said.
“At one time we were struggling at 80-5 and I knew first we have to get the runs they got, so I just try to play positive and it helped. “I think if we get early wickets tomorrow and keep them down to below 250 then that will be a winning score.”
Chandimal was finally dismissed by part-time spinner Haris Sohail, caught at backward point after he mistimed a cut. He hit 10 boundaries in his 143-ball knock.
The extended two-and-a-half hour first session belonged to Pakistan who took three early wickets after Sri Lanka resumed at 64-3.
It were Abbas and Shaheen who rattled the Sri Lankan batting. Abbas had nightwatchman Lasith Embuldeniya caught in the slip for 13 before left-armer Afridi dismissed Angelo Mathews, also for 13. De Silva, who scored a century in the first Test, batted with grit to frustrate Pakistan and take Sri Lanka to 170-6 at lunch.
Shaheen broke the stand by luring De Silva into hooking straight into the hands of deep square-leg fielder Abbas, who held a running catch. Perera also added an invaluable 36 for the ninth wicket with Vishwa Fernando to increase Sri Lanka’s lead before Shaheen took the last two wickets in three balls.
Shahen’s previous best of 4-64 came in the Centurion Test against South Africa earlier this year. Perera hit six boundaries and a six in his 84-ball stay.
The Test series — part of the ongoing World Test championship — is the first in Pakistan since a militant attack on the Sri Lankan team bus in 2009 suspended international cricket in the country.