Tharanga helped the home side reach a comfortable 113-1 in their second innings at tea on the third day. Kumar Sangakkara (29) was the other not out batsman at the break here on Tuesday.
Sri Lanka, who gained a thin nine-run first innings lead, looked set to knock up a sizeable total as Pakistan's seamers struggled for success after a fine show in the first innings.
They only managed the wicket of veteran opener Sanath Jayasuriya (13), who was caught down the leg-side when he top-edged an attempted pull off seamer Mohammad Asif.
Tharanga, 21, added 53 with Jayasuriya and an unfinished 60 with Sangakkara for the second wicket during his second Test half-century and has so far hit 10 fours on a pitch that seems to be playing easier.
Sri Lanka earlier put up a spirited display to restrict Pakistan to 176, with their bowlers removing the last six batsmen for 52 to gain a narrow lead.
Pakistan, resuming on 124-4, were in trouble as paceman Farveez Maharoof returned his best bowling figures of 4-52.
Maharoof, who captured two wickets off successive balls on Monday, struck in his first over of the morning. He removed skipper Inzamam-ul Haq (31) off his third ball as the batsman nicked one to wicket-keeper Sangakkara.
The 21-year-old, playing his ninth Test, struck again a few overs later when he bowled Abdul Razzaq with an in-swinger to reduce Pakistan to 138-6.
He received splendid support from off-spinner Muttiah Muralitharan, who picked up three wickets Tuesday morning to ensure there was no rearguard action. Paceman Lasith Malinga also finished with three scalps.
The entire first day was washed out by rain.
The second and final Test will start in Kandy on April 3.