Glenn Maxwell was unbeaten on 8 and Matthew Wade was batting on five at the interval, with just the tailenders to come.
Shakib was the pick of the bowlers with five wickets, while Taijul snapped up three and Mehidy claimed two.
One would have hardly imagined Australia to lose from a commanding position when they started on the fourth day chasing 265 for a win with their two top batsmen - Steve smith and David Warner at the crease.
It's often said that the biggest weapon of an athlete in his mind and Bangladesh proved exactly that.
Shakib - who finished with 10 wickets for the match - quickly added the wicket of Smith when he edged behind attempting a cut shot and the same stroke brought Peter Handscomb (15) undone shortly after.
But Smith settled himself and shrugged off the early nerves while Warner played what is already one of his best - if not the best - knock in such conditions.
Australia was cruising towards the win before Warner's wicket and all of a sudden they were struggling to keep their wickets intact.
Shakib was named Man of the Match, and said: "It feels great to contribute for the team". Later, it was revealed that the 26-year-old will not play in the second and final Test against Bangladesh on September 4. Against England [last year] also, we were very close in the first test and beat them in the second test. "It's disappointing. I think we probably let ourselves down in the first innings with the bat", Smith said. Australia were hampered by losing the toss as well as being without an injured Josh Hazlewood for much of Bangladesh's second innings and would want to make a stronger comeback.
Shakib (5-85) celebrated his 50th Test appearance by scoring 84 in the first innings and finishing with a 10-wicket match haul, a performance worthy of his status as the world's top-ranked Test all-rounder.
As anticipation builds for Day Four, the last word in the first of this two-match series looks set to lie with the bat of Warner - seeking his 19th Test century - or the bowling of Shakib.
Nathan Lyon and Pat Cummins combined for 29 runs in a ninth-wicket stand to provide Australia with some hope before Hasan broke through, dismissing Lyon for 12. "It was pretty hard batting here in the second innings and I thought we did pretty well to get 240 in the end".