Yeovil had led 2-0 at half-time through John Lundstram and Ishmael Miller but another goal from Chelsea's on-loan striker Patrick Bamford and a Craig Bryson drive put Derby level before Martin glanced in a free-kick in the fourth minute of added time.
It was raining heavily when the game kick-off and Derby zipped the ball around to create an early shooting chance for Bamford that struck a Yeovil defender before Chris Martin had a clear opening from 12 yards in the ninth minute but Shane Duffy made a vital block.
Derby's ability to move the ball quickly was making life difficult for the visitors and when Andre Wisdom burst forward from right back in the 15th minute, he set up Martin for a first-time shot from 15 yards which narrowly cleared the bar.
Another slick Derby move saw Bryson slice a shot wide before a Simon Dawkins drive was deflected against a post and some Bamford trickery on the right took him past three challenges only for the ball to run away from him.
It was starting to look a long night for Yeovil but totally against the run of play they took the lead in the 25th minute when Lundstram surged forward and drove a low right-footed shot into the bottom corner from 20 yards.
Derby had strong claims for a penalty waved aside when Martin appeared to be shoved over in the 32nd minute but Yeovil scored again two minutes later when Lundstram broke quickly and released Miller who brushed off Richard Keogh to fire a cross-shot inside Lee Grant's left post.
Derby made an attacking change at half-time, replacing John Eustace with Jamie Ward, and they cut the arrears in the 50th minute when Dawkins pulled the ball across and Bamford scored with a diving header.
Yeovil almost scored again when Miller set up Joel Grant who was foiled at his near post by Grant and the Derby goalkeeper made another vital save when he tipped over a deflected free kick.
Bamford smashed a shot against a post in the 62nd minute and Craig Forsyth fired over from eight yards as Derby pressed forward for the equaliser which came in the 87th minute.
Will Hughes cleverly held the ball on the right of the Yeovil box before slipping it to Bryson who swept a right foot shot into the bottom right corner of the net for his 12th goal of the season.
Time was almost up when Bryson flighted in a free-kick from the right edge of the box and Martin sent it skimming into the net to seal a remarkable comeback.