A dramatic extra-time strike by Abdulai Bell-Baggie put Tranmere through 2-1 in an incident-packed Capital One Cup first-round tie at Chesterfield.
The substitute pounced in the second minute of stoppage time after Cole Stockton had given the visitors a 94th-minute lead before Jack Lester levelled in the 109th minute.
Tranmere almost took the lead in the 24th minute when a header from Jean- Louis Akpa Akpro was tipped onto the underside of the bar by Tommy Lee and bundled behind for a corner.
They should have scored in the 39th minute when Sam Hird was caught on the ball by Liam Palmer, who was left with only Lee to beat but side-footed wide.
Lee made another excellent save in the 57th minute when he tipped away a low shot from Stockton and the striker saw a shot come back off a post eight minutes later.
Chesterfield went close in the 72nd minute but Jordan Bowery's low shot was held by Owain Fon Williams and the game went into extra-time before Tranmere finally broke through in the 94th minute when Akpa-Akpro put Stockton in on the right and he lashed a shot from 12 yards into the top corner.
But Chesterfield equalised in the 109th minute when Lester got in on the left and chipped over Fon Williams and the tie was held up for four minutes to repair one of the nets.
It looked to be heading for penalties when Bell-Baggie cut in from the left and fired a shot into the top corner to put Tranmere through.