Hearts dominated the first half, Jamie Walker scoring a third-minute penalty after Kevin Gomis brought him down.
Callum Paterson headed home Don Cowie's free-kick early on the resumption.
But Dundee captain Darren O'Dea drilled home to cut the deficit, Paul McGowan smashed home the equaliser before Paterson headed into his own net.
Victory, their fourth in eight games, lifted the Dark Blues into seventh place, while fourth-placed Hearts are now without a win in four.
Winger Walker has been the subject of much discussion this season with his twisting runs regularly inducing defenders into rash challenges inside the box.
And once again he earned his team a penalty after being played in by Bjorn Johnsen. The 23-year-old picked himself up to send Scott Bain the wrong way for his fifth successful spot-kick, and eighth goal, of the season.
Walker was ably assisted by Paterson, who Hearts director of football Craig Levein said earlier this week will not be leaving the club in January unless they receive a seven-figure offer.
When the Scotland full-back headed home Don Cowie's free-kick three minutes into the second period, his eighth goal of the season and 37th for the club overall, the visitors looked destined for all three points.
The home fans made their frustrations known as a fifth home defeat of the season loomed.
Manager Paul Hartley responded by replacing midfielder Mark O'Hara with Paul McGowan, and the momentum of the game changed.
O'Dea pulled one back with a rare right-foot strike after the Hearts defence failed to clear the ball from their own box.
With confidence visibly growing, McGowan latched onto a ball from Craig Wighton and clipped the ball over the advancing Jack Hamilton to draw Dundee level.
A neck injury to Hearts midfielder Don Cowie, who was stretchered off after a delay of seven minutes and taken to hospital, appeared to adversely affect the visitors.
The 1400 Hearts fans who made the trip to Dundee could barely believe their team's collapse when the hosts completed their comeback in the 93rd minute, Haber getting up to meet a Tom Hateley free-kick from close range, only for Hearts defender Paterson to direct a header into his own net.
Hearts should have been out of sight at half time. Paterson, Walker, Arnaud Djoum and Krystian Novak all came close to adding further goals to Walker's opener, and Cathro must wonder what his players have to do to get that first win of his tenure.
They have two more opportunities in the next week before the winter break, with Kilmarnock - on Tuesday - and Aberdeen - next Friday - both visiting Tynecastle.
Dundee boss Paul Hartley:
"The first half we were really poor, the game could have been dead and buried. That's the worst we have been for a long time.
"The second half we showed a real grit, determination and desire to stay in the game at 2-0 down and we always thought we would get chances. Once we got the goal back to make it 2-1 we could feel momentum building.
"I'm really proud of the players as it has been a tough season so far. They showed great character tonight. They could have gone into a shell but we kept going. Hearts were excellent in the first half but we changed a couple of things and it paid off."
Hearts head coach Ian Cathro:
"I didn't see that coming. Nobody did. We were entirely in control of the game. Our performance was good and we were in a dominant position. Ultimately we have made mistakes and we have thrown the game away. As simple as that.
"There was a break in play, a couple of changes but all we were tasked with doing was managing the game properly and staying together. I think everyone is aware there are young players in the team but there are some experienced players also. When we are in these positions we have to win the games.
"It's now been two weeks. I have learned an awful lot about everyone, about us. The only thing I have learned about myself is that I was right when I thought a long time ago that I was strong enough to deal with these things. I am confident and relaxed in the fact and fortunate that I am strong and these challenges just add to making me a little bit better."
Match ends, Dundee 3, Heart of Midlothian 2.
Second Half ends, Dundee 3, Heart of Midlothian 2.
Substitution, Heart of Midlothian. Faycal Rherras replaces Liam Smith.
Goal!  Dundee 3, Heart of Midlothian 2. Marcus Haber (Dundee) header from very close range to the high centre of the goal. Assisted by Tom Hateley following a set piece situation.
Liam Smith (Heart of Midlothian) is shown the yellow card for a bad foul.
Foul by Liam Smith (Heart of Midlothian).
Cameron Kerr (Dundee) wins a free kick in the defensive half.
Substitution, Heart of Midlothian. Tony Watt replaces Jamie Walker.
Attempt saved. Craig Wighton (Dundee) header from the centre of the box is saved in the top centre of the goal.
Corner,  Heart of Midlothian. Conceded by Kostadin Gadzhalov.
Kevin Holt (Dundee) is shown the yellow card for a bad foul.
Foul by Kevin Holt (Dundee).
Jamie Walker (Heart of Midlothian) wins a free kick in the defensive half.
Attempt missed. Callum Paterson (Heart of Midlothian) left footed shot from outside the box misses to the left.
Attempt missed. Craig Wighton (Dundee) left footed shot from the left side of the box is close, but misses the top left corner.
Foul by Julen Etxabeguren Leanizbarrutia (Dundee).
Bjorn Johnsen (Heart of Midlothian) wins a free kick on the left wing.
Tom Hateley (Dundee) wins a free kick in the attacking half.
Foul by Liam Smith (Heart of Midlothian).
Corner,  Dundee. Conceded by Robbie Muirhead.
Corner,  Dundee. Conceded by Igor Rossi.
Attempt blocked. Tom Hateley (Dundee) right footed shot from the right side of the box is blocked.
Attempt missed. Callum Paterson (Heart of Midlothian) left footed shot from outside the box misses to the right.
Attempt saved. Robbie Muirhead (Heart of Midlothian) right footed shot from outside the box is saved in the top centre of the goal.
Attempt missed. Bjorn Johnsen (Heart of Midlothian) header from the centre of the box misses to the right.
Goal!  Dundee 2, Heart of Midlothian 2. Paul McGowan (Dundee) right footed shot from very close range to the bottom right corner. Assisted by James Vincent.
Substitution, Heart of Midlothian. Robbie Muirhead replaces Don Cowie because of an injury.
Attempt missed. Jamie Walker (Heart of Midlothian) left footed shot from the centre of the box is too high.
Foul by Arnaud Djoum (Heart of Midlothian).
Kostadin Gadzhalov (Dundee) wins a free kick in the attacking half.
Corner,  Heart of Midlothian. Conceded by Cameron Kerr.
Goal!  Dundee 1, Heart of Midlothian 2. Darren O'Dea (Dundee) right footed shot from the centre of the box to the bottom right corner. Assisted by Marcus Haber.
Foul by Igor Rossi (Heart of Midlothian).
Marcus Haber (Dundee) wins a free kick on the right wing.
Substitution, Dundee. Paul McGowan replaces Mark O'Hara.
Attempt saved. Bjorn Johnsen (Heart of Midlothian) right footed shot from outside the box is saved in the centre of the goal.
Jamie Walker (Heart of Midlothian) wins a free kick in the attacking half.
Foul by Tom Hateley (Dundee).
Goal!  Dundee 0, Heart of Midlothian 2. Callum Paterson (Heart of Midlothian) header from very close range to the top left corner. Assisted by Don Cowie following a set piece situation.
Callum Paterson (Heart of Midlothian) wins a free kick on the right wing.
Dundee came from two goals down to stun Hearts with an injury-time winner and leave Ian Cathro still waiting for his first win as head coach.