At close Wednesday on day four, Bangladesh were 195-4 and needing 189 more runs to make Australia bat again after conceding a 384-run first-innings lead.
Shahriar Nafees (75) and Aftab Ahmed (one) were the not-out batsmen.
Gillespie, whose previous Test best was 54 not out, ended on 201 not out -- a record for a nightwatchman -- as Australia declared on 581-4 in reply to Bangladesh's first-innings 197.
The lower-order batsman, who had never got to three figures even in a first-class game, gave himself a wonderful present on his 31st birthday.
Coming in at number three towards the end of the first day, Gillespie batted through two rain-hit days to surprise everyone including himself.
"I never expected it in my wildest dreams... so it's pretty surreal, pretty bizarre actually," said the fast bowler.
"Nothing's really changed. I suppose it will sink in over the next couple of days but I can't believe I'm talking about my batting. That's what I can't believe."
Gillespie and Michael Hussey, who also achieved a career-best innings, allowed the tourists to declare 25 minutes after lunch. They had plundered runs at will in the morning session after resuming on 364-3.
Gillespie, who had completed his maiden ton on Tuesday, batted on with ease and his fourth-wicket stand with Hussey (182) was worth 320. Gillespie's innings lasted 425 balls and included 26 fours and two sixes.
He got past 200 with a glance off left-arm spinner Mohammad Rafique and went back to the pavilion with his hands raised and nodding his head in disbelief, as captain Ricky Ponting made the declaration.
The previous highest mark for a nightwatchman Tony Mann's 105 for Australia against India at Perth in 1977.
Hussey got to his fourth century in 11 Tests with a drive through covers off paceman Shahadat Hossain and went on to surpass his previous highest of 137 against the West Indies in Hobart last year.
Hussey, 93 overnight, smashed 21 fours and a six off 203 balls before holing out to Hossain at the square-leg fence off part-time seamer Ahmed in a bid to step up the run-rate.
In reply, Bangladesh lost opener Javed Omar (19) early as Brett Lee trapped him leg-before.
Captain Habibul Bashar (49), who survived an easy chance on zero when Shane Warne dropped him at slip off Gillespie, was dismissed by leg-spinner Warne himself as Matthew Hayden caught him at the same position.
Warne also dismissed Rajin Saleh (five) soon after, caught by Ponting at silly-point, and then bowled Mohammad Ashraful (29) round the legs for his third scalp.
But first-match centurion Nafees continued his fine form and had so far hit nine fours off 166 balls during his second half-century in six matches.
Australia were surprisingly run close in the first Test before winning by three wickets.