Kaushal Silva (38) and Kumar Sangakkara (36) added 75 after Tharanga fell lbw to Junaid Khan for 19.
Sri Lanka off-spinner Dilruwan Perera took the last five Pakistan wickets as the tourists were finally dismissed for 451 in their first innings, anchored by a magnificent 177 from Younus Khan.
The 36-year-old had dealt Perera some harsh treatment in the morning session but the spinner delivered some retribution by dismissing him in the fifth over after lunch.
Younus advanced down the pitch but could only lob an easy catch to Kithuruwan Vithanage at short mid-wicket.
Sarfraz Ahmed (55) was next to fall trying to attack Perera, the right hander's smash through the leg side going straight to silly mid-on fielder Angelo Mathews.
That left the tourists on 388-7 with Saeed Ajmal and Abdur Rehman taking Pakistan past 400 before Perera struck again to remove Ajmal for 12 after he flicked a ball to Mahela Jayawardene at leg slip.
Rehman became the fourth Pakistani to record a half century in the innings with an entertaining knock featuring six fours and a six before he fell for 50, attempting one shot too many as Kumar Sangakkara took a catch at long off.
Perera then ended the innings when Jayawardene held onto another smart catch as Junaid Khan attempted a sweep and the ball grazed his glove.
Perera finished with figures of 5-137 as the hosts fought back after a frustrating morning session where their only breakthrough came with the dismissal of Asad Shafiq for 75.
The right-handed batsman failed to read the arm ball from Rangana Herath and was trapped leg before.
Image: Pakistan's Younis Khan celebrates after completing 150 runs on the second day of the first Test against Sri Lanka in Galle
Photograph: Dinuka Liyanawatte/Reuters
Cricket Buzz: Sri Lanka drop Chandimal, Mendis for Pakistan Tests
South Africa lose Petersen in steep run chase
Younis century rescues struggling Pakistan
4 Indians evacuated from Gaza on its deadliest day
Why Kallis ranks as one of greats of the modern game