Kieran Powell notched up his second century of the match before Bangladesh brought alive the first Test by grabbing five West Indian wickets in 13.1 overs on Friday to raise the spectre of an unlikely victory.
The visitors will take a 215-run lead into the final day but will struggle to add to their tally as the only recognised batsman remaining, Shivnarine Chanderpaul, is unwell and may not be able to bat.
West Indies reached 244-6 at the close on the fourth day and the hosts will fancy their chances of notching up their first Test win against a top side having scored their highest ever total of 556 in the first innings.
Powell became the ninth Caribbean batsman to score two centuries in a single Test after scoring a patient 110 from 197 balls, adding to the 117 he amassed in the first innings.
He shared a 189-run second-wicket stand with Darren Bravo, mainly thanks to the butter fingers of Zunaed Siddique who dropped the batsman on 17 at slip.
Bangladesh got an early breakthrough when Rubel Hossain had Gayle caught behind for 19, but Powell and Bravo denied them any chance of gaining an upper hand with their prolific stand.
Rubel dismissed Bravo for 76 before off-spinner Sohag Gazi forced Marlon Samuels (1) to loft a catch to Shahriar Nafees at forward short leg to trigger a late West Indian collapse.
Left-arm spinner Shakib Al-Hasan induced an edge from Powell to end his knock, which included 12 fours and a six, and trapped first innings centurion Denesh Ramdin for five.
West Indies sent Veerasammy Permaul in ahead of Shivnarine Chanderpaul, who fell ill after smashing a double century in the first innings, and the debutant struck two fours in the first two balls he faced to ease some pressure.
But Gazi bowled him for 10 on the final ball of the day to cap in a remarkable session for Bangladesh.
Earlier, Bangladesh's Nasir Hossain missed out on his maiden Test century when he was out for 96, caught by Gayle at slip off Tino Best.
Nasir resumed on 33 and added 121 runs for the seventh wicket with fellow overnight batsman Mahmudullah, who made 62.
The duo helped Bangladesh to overhaul their previous highest Test total of 488 against Zimbabwe at Chittagong.
Following Mahmudullah's dismissal with the total on 489, Nasir kept his focus and nudged a single to take Bangladesh over the 500-run mark for the first time.
Bangladesh then snatched an unlikely 29-run first-innings lead courtesy of Nasir's 61-run ninth wicket stand with Shahadat Hossain, the last man out as Sunil Narine bowled him for his third wicket of the day.
Scoreboard:
West Indies first innings: 527-4 declared
Bangladesh first innings (overnight 455-6)
T Iqbal c Narine b Sammy 72
Z Siddique c Bravo b Rampaul 7
S Nafees c Ramdin b Rampaul 31
N Islam c Ramdin b Sammy 108
Shakib Al Hasan c Sub b Rampaul 89
M Rahim c&b Permaul 43
N Hossain c Gayle b Best 96
Mahmudullah c Powell b Narine 62
S Gazi b Narine 4
S Hossain b Narine 13
R Hossain not out 0
Extras: (b-8 lb-12 w-3 nb-8) 31
Total: (148.3 overs) 556 all out
Fall of wickets: 1-25, 2-88, 3-119, 4-286, 5-362, 6-368, 7-489, 8-493, 9-554, 10-556
Bowling: Ravi Rampaul 32-2-118-3, Tino Best 23-3-77-1 (w-3), Darren Sammy 23-3-83-2, Sunil Narine 32.3-5-148-3, Veerasammy Permaul 29-7-75-1, Chris Gayle 3-0-14-0, Marlon Samuels 6-0-21-0
West Indies second innings
C Gayle c Rahim b Rubel 19
K Powell c Rahim b Shakib 110
D Bravo c Rahim, b Rubel 76
M Samuels c Shahriar b Gazi 1
D Ramdin lbw b Shakib 5
D Sammy not out 15
V Permaul b Gazi 10
Extras (b-1 lb-3 nb-4) 8
Total (64.5 overs) 244 for six
Fall of wickets: 1-20 2-209 3-212 4-218 5-225 6-244 To bat: S. Chanderpaul, S. Narine, T. Best, R. Rampaul
Bowling (to date): Sohag Gazi 18.5-2-63-2 Rubel Hossain 14-4-35-2, Mahmudullah 3-0-12-0, Shahadat Hossain 7-1-34-0, Shakib Al Hasan 11-2-56-2 , Naeem Islam 8-0-22-0, Nasir Hossain 3-0-18-0.