The left-handed opener hit an unbeaten 110 as Sri Lanka reached 223-5 at tea on the second day in reply to the home side's 234. Tillakaratne Dilshan was the other not out batsman on 31.
Tharanga, 21, was involved in a crucial 124-run stand for the fifth wicket with captain Mahela Jayawardene (49) after Sri Lanka were reduced to 43-4 at one stage.
Tharanga, playing only his third Test, smashed 14 fours and two sixes and found able support from his skipper on Thursday.
Jayawardene hit seven fours before he was out playing a pull shot straight to Mushfiqur Rahim at deep mid-wicket, giving part-time leg-spinner Mohammad Ashraful a wicket off his first ball.
The Sri Lankan captain found himself in the middle after a twin strike from paceman Shahadat Hossain had rocked the middle order.
Hossain removed Thilan Samaraweera and Kumar Sangakkara early in the first session as Sri Lanka struggled after resuming on 25-2.
The seamer struck with the last ball of his first over of the day as Samaraweera (20) went for a drive and edged the ball to wicketkeeper Khaled Mashud.
Hossain, who had dismised Malinga Bandara on the first day, picked up another wicket with the first ball of his next over when vice-captain Sangakkara (zero) was given lbw.
The paceman had also impressed with a four-wicket haul in the first innings of the opening Test in Chittagong, which Bangladesh lost by eight wickets.