Fast bowler Asitha Fernando bowled Shafique, who hit a match-winning 160 in the opener of the two-Test series, on the second ball of Pakistan's reply after a thick inside edge off the bat rattled on to the stumps at Galle.
Pakistan were 15 for one at lunch with left-handed opener Imam-ul-Haq on four and skipper Babar Azam on seven. They trail by 363 runs.
Sri Lanka resumed on 315-6 in former captain Angelo Mathews' landmark 100th Test, with overnight batsman Niroshan Dickwella making 51 and a useful cameo of 35 by number nine Ramesh Mendis.
Fast bowler Naseem Shah and leg-spinner Yasir Shah claimed three wickets each to end Sri Lanka's innings in the first session.
Dickwella, a left-hand wicketkeeper-batsman, added nine to his overnight 42 before Naseem sent him back.
Naseem struck twice in the opening session with his express pace to return figures of 3-58.
His bouncer to debutant Dunith Wellalage saw the left-hander caught at second slip for 11 after attempting to evade the ball, which took his glove.
Ramesh frustrated the opposition bowlers with four fours and one six before being bowled by Yasir.
Opener Oshada Fernando (50), Dinesh Chandimal (80) and Mathews (42) hit key knocks on Sunday after the hosts elected to bat first.
Sri Lanka skipper Dimuth Karunaratne did not take the field on Monday as he is being treated for back pain, with deputy Dhananjaya de Silva standing in as captain.