More on KentOnline
Substitute Tom Hitchcock came off the bench to fire in a hat-trick and leave the Gills empty-handed at Priestfield.
Gillingham conceded after just 13 seconds but took the lead with goals either side of the break, from Adebayo Akifnenwa and Myles Weston.
Bradley Dack struck for the Gills either side of a double from substitute Hitchcock.
The Rotherham player then popped up in stoppage time to lob keeper Stuart Nelson and win it for the visitors.
There was a change at the back for the Gills as Ryan Inniss came into the centre of defence to partner Adam Barrett. Akinfenwa also returned to the starting XI.
Gillingham were hoping for a win which would all-but end their fears of League 1 relegations.
But the visitors – without a win at Priestfield since 1988 – made a stunning start. The Gills hadn’t even touched the ball and found themselves a goal down.
From kick-off, Rotherham surged forward and Keiran Agard had a simple finish from Nicky Adams’ cross.
It was looking bad for Gills in the opening stages. The Gills lined up with a 4-2-3-1 formation but it wasn’t clicking for them.
But once Akinfenwa and McDonald started to link up, the Gills started playing. That came after a few more scares, including a shot from James Tavernier, that went narrowly wide, after he had been gifted with a chance following Barrett’s weak clearance.
Bradley Dack, who was starting a game for the first time in over a month, almost got on the end of a McDonald cross. The same player put a 25-yard effort wide after Akifnewa had teed him up.
Gillingham were grateful that referee Steven Rushton didn’t award Rotherham a penalty, when Joe Martin tangled with Adams.
The equaliser came on the half-hour as a simple free-kick routine paid off. Dack whipped in the set-piece and Akinfenwa nodded home from close range for his 10 of the season.
An Adams effort came close for the visitors early in the second half but the Gills got their noses infront in the 57 minute as Elliott Hewitt picked out Weston’s run and the winger slid the ball home.
The lively Weston almost extended Gills’ lead moments later. He turned a defender before firing in a shot that keeper Adam Collin did well to get down to save. Hewitt also came close, blasting a powerful effort into the Rainham End.
Rotherham levelled with 69 minutes gone when substitute Hitchcock beat the off-side trap to get on the end of Richard Smallwood’s ball forward.
A looping Barrett header was well saved by keeper Adam Collin as both sides searched for a winner. At the other end a Pringle shot was saved by the feet of Nelson with nine minutes left.
Dack capitalised on a mistake from defender Kari Arnason and lobbed keeper Collin to put the Gills back infront of 83 minutes.
But two minutes later and it was all-square again. Barrett missed a clearance and Hitchcock was there to make him pay, as he poked home his second of the match.
Hitchcock was the man to fire Rotherham into a 4-3 lead in injury-time. Once again he found himself in space in the box and curled home over Nelson.
Gillingham: Nelson, Martin, Harriman, Inniss, Barrett, Gregory (German 90mins), Hewitt, Weston (Lee 71mins), Dack, Akinfenwa (Linganzi 78mins), McDonald. Subs not used: Baxter, Birchall, Smith, Hessenthaler.
Rotherham: Collin, Tavernier, Skarz, Arnason, Frecklington (Milsom 81mins), Revell, Pringle, Morgan, Agard, Smallwood (O’Connor 90mins), Adams (Hitchcock 60mins). Subs not used: Shearer, Davis, Thomas, Vuckic.
Attendance: 6,027 (420 visitors)