Dilshan, who scored 162 and 143 with the bat, took 4-10 in 4.2 overs to help dismiss Bangladesh for 158 after a 92-run sixth-wicket stand between Mushfiqur Rahim (43) and Shakib Al Hasan (46) took the hosts to 144-6 in the unlikely pursuit of 624 to win.
Al Hasan was stumped by Prasanna Jayawardene off Dilshan, who then trapped Mehrab Hossain lbw for 5, had Mashrafe bin Mortaza caught behind for 0 and then bowled Shahadat Hossain for 1 at Chittagong Divisional Stadium.
Earlier, Sri Lanka declared on 447-6 at lunch with Thilan Samaraweera (77) and Chamara Kapugedera (59 not out) scoring half-centuries and add to Dilshan's hundred and Kumar Sangakkara's 54.
Bangladesh had lost both opening batsmen by the time the score was 22. Unorthodox finger spinner Ajantha Mendis had Imrul Kayes caught at first slip by Mahela Jayawardene for five and Tamim Iqbal was caught behind for 17 off Chaminda Vaas.
Mendis dismissed Junaid Siddique lbw for four before having Bangladesh captain Mohammad Ashraful caught behind for seven and ultimately finished with figures of 3-57. Dilhara Fernando then bowled Raqibul Hasan for 10 to leave the hosts at 52-5.
Sri Lanka had resumed the day on 296-4 and Al Hasan made an early breakthrough for Bangladesh, trapping Samaraweera lbw to end his 145-run partnership with Dilshan.
Dilshan then batted with Kapugedara to complete his seventh Test century before being bowled by Enamul Haque for 143. Dilshan's hundred came off 130 balls and included 11 boundaries.
Ashraful took 2-56, while Haque had figures of 2-109.
Sri Lanka won the first Test in Dhaka by 107 runs.