Jack Stretton gave the Rams the lead in the 77th minute before Harrison Burrows equalized in the first minute of second-half stoppage time for Posh.
The match appeared headed for a draw until Siriki Dembele won it in the 100th minute for the hosts, who registered their first win in the EFL Championship in nine and a half years.
Story of the match
There wasn't much action in the opening minutes of the game until the 16th minute when a direct run from Festy Ebosele, who delivered a cross that is turned behind. The subsequent corner found Graeme Shinnie, who saw his shot comfortably saved by Christy Pym.
Tom Lawrence then dribbled just beyond the center circle, looked up and attempted a shot that flew well wide of the left-hand upright. At the other end, Dan Butler and located Jonson Clarke-Harris with a deep cross to the far post, but he could only head over.
Peterborough would have the best chance of the game up to that point as in the 33rd minute as Clarke-Harris picked up possession 35 yards from goal and turns to shoot, with his shot hitting the inside of Kelle Roos' right leg.
A minute before halftime, Lawrence floated a delivery to the far post, which goes totally unchallenged and drops behind for a goal-kick, which was the last action of the first half.
Posh were on the attack right out of halftime as Jorge Grant thundered a shot from 18 yards that Roos dove to his right to hold. Just past the hour mark, Mark Beevers guided a cross from the left side of the area, which Nathan Thompson glanced over the bar.
Louie Sibley cleverly slid the ball across the six-yard box, where Stretton couldn't stretch far enough to connect with it. Shortly after, the 19-year old substitute would give the Rams the lead.
A second corner came in from the right and like a game of pinball, he prevented Frankie Kent from clearing and fired past Pym to make it a 1-0 game.
In the 89th minute, Posh came close to tying the game as Burrows evaded his marker and sent a teasing ball across the face of goal that Clarke-Harris couldn't stretch far enough as the ball flashed across.
The first minute of extra time saw Peterborough get their equalizer as Derby were caught napping from a quick free-kick. Joe Ward played a brilliant ball across the face of goal and Burrows popped up with the simplest of finishes.
After going close twice more, the hosts found a winner. Ward delivers another superb ball in from the right which causes all sorts of problems for the Rams defense. Byrne got the ball stuck beneath his feet and Dembele rifled a stunning effort past Roos into the bottom corner.
Man of the match: Harrison Burrows
The second-half sub proved to be the difference, striking early in stoppage time to level and he used his pace and energy to repeatedly threaten the Derby goal.