Australia, who resumed the day on a precarious 18-3, were bowled out early in the final session for 217 to hand the hosts a 43-run first-innings lead.
By stumps they had increased that to an 88-run advantage for the loss of one wicket.
Shakib, who finished with 5-68 and also top-scored in Bangladesh's first innings with 84, was ably supported by off-spinner Mehedi Hasan.
Mehedi claimed three wickets for 62 including the prized scalp of skipper Steve Smith for eight.
More From This Section
Slow left-armer Ashton Agar ended a confident 43-run opening stand when he had Soumya Sarkar (15) caught by Usman Khawaja at long-on after several attempts.
Australia also had Agar to thank for helping get them close to Bangladesh's first innings total of 260 after their regular batsmen struggled against spin.
Agar, batting at number nine, made an unbeaten 41 and shared a crucial stand of 49 with Pat Cummins, taking Australia past the 200 mark after Shakib and Mehedi had the visitors on the ropes.
When he was on 11 Cummins survived a dropped catch by Shafiul Islam at cover off Shakib and was then reprieved by the third umpire after being given out caught behind.
Shakib finally bowled Cummins for 25 in the evening session and then had Josh Hazlewood caught by Imrul Kayes at short leg to end Australia's innings and complete his 16th five-wicket haul in Tests -- at least one against each of the nine Test teams he faced.
The 23-year-old took the attack to the opposition but ran out of partners.