Jack Dunn scored a stunning hat-trick as Morecambe moved into the second round of the EFL Cup after a nine-goal thriller at the New York Stadium.
The Shrimps started the game superbly and took the lead after just six minutes through Cole Stockton.
The on-loan Tranmere man took the ball on the edge of the area and produced a stunning shot that flew past Lewis Price in the home goal.
The goal sparked the Championship outfit into life and they almost equalised on 14 minutes when a sweetly struck shot from Jon Taylor from just inside the area hit the post.
Rotherham then forced a number of half chances with young striker Jerry Yates and midfielder Richie Smallwood both dragging shots wide from good opportunities but the half ended with the Shrimps on top as Tom Barkhuizen had two golden chances to extend Morecambe's lead but saw two efforts well saved by Price.
The Shrimps started the second half sharply with Mullin shooting wide and Stockton missing a golden opportunity to double their lead when he missed an open goal from eight yards out after Price had parried Barkhuizen's shot.
He was made to pay for his miss a few moments later as Rotherham levelled from a soft penalty when Greg Halford scored from the spot after he had been fouled by Ryan Edwards.
The goal gave the home fans a lift but they were silenced again on 68 minutes when substitute Dunn put the Shrimps ahead for the second time with a superb first-time finish from a left-wing cross.
The Shrimps looked good value for the lead but were undone by two goals in two minutes.
Rotherham levelled on 82 minutes when Tom Thorpe got in behind Luke Conlan on the right and pulled the ball back for Jerry Yates to beat Roche with a low shot from the edge of the area.
The turnaround was complete when Anthony Forde beat Roche from a tight angle a minute later to put his side ahead for the first time in the match.
The Shrimps fought back however and Dunn was on the scoresheet again in injury time when he was brought down in the box and beat Price from 12 yards to set up extra-time after a pulsating 90 minutes.
After a goalless first period the Shrimps then took the lead again on 113 minutes when Kevin Ellison scored from close range after Dunn's close range shot was blocked on the line.
The Liverpool loanee then secured his hat-trick with a top-quality finish with one minute to go after being found by Ellison to make it 5-3.
Yates pulled another one back for the home side with a close range finish but the Shrimps held on to win on another memorable cup night for Jim Bentley's side.
Rotherham: Price, Thorpe, Halford, Wilson (rep Wood 46), Warren, Taylor, Smallwood, Vaulks, Allan (rep Forde 76), Yates, Forster-Caskey. (rep Ward 63) Subs not used: Camp, Kelly, Bailey-King, Muskwe.
Morecambe: Roche, Wakefied, Edwards, Whitmore, Conlan; Kenyon (rep Fleming 87), Rose, Barkhuizen, Mullin (rep Dunn 63), Molyneux, Stockton (rep Ellison 87) Subs not used: Nizic, McGowan.
Referee: S Stockbridge.
Attendance: 3,793 (118 away fans)