Nasir Hossain upped the ante and along with the tail notched up his maiden hundred in 147 balls, only to get out in the next over.
Sri Lanka bowlers toiled for 195 overs as Bangladesh ended their first innings at 638 with a lead of 68 runs. Nuwan Kulasekara, Shaminda Eranga, Rangana Herath, Ajantha Mendis and T Dilshan picked two wickets each.
In reply, Sri Lanka lost Dimuth Karunaratne early but Tillakaratne Dilshan and Kumar Sangakkara compiled a 99-run stand to finish day 4 at 116 for 1 leading Bangladesh by 48 runs.
Dilshan scored a breezy fifty that came off 68 balls. At stumps Dilshan was batting on 63 and Sangakkara on 49.
Mohammed Ashraful and Rahim could only add six runs to their overnight partnership of 261, before the former fell ten runs short of double hundred with Rangana Herath taking the wicket.
Day four at Galle belonged to Bangladesh and records as the visitors racked up their first 600 plus score with Mushfiqur Rahim becoming the first Bangladesh player to score a double hundred in Tests.
Rahim then compiled a 106-run stand with Nasir Hossain as he got to his maiden double hundred Bangladeshs first in Test cricket since their inception in 2001. Rahim got to his 200 in 320 balls aided by 22 fours and a six. He got out a ball later off Kulasekara.