Two late Grant McCann penalties gave Peterborough a Championship lifeline and dented Cardiff's promotion hopes.
Aron Gunnarsson had put Cardiff ahead, scuffing home from close range after Ben Turner flicked on a corner.
But when Don Cowie lost the ball near his own area the midfielder lunged in on Posh's Mark Little, with substitute McCann converting the spot-kick.
Then Dwight Gayle went tumbling under a Matt Connolly tackle and McCann stepped up to beat David Marshall again.
The result, which saw Peterborough complete the double over the Welsh side, continues a miserable run for Cardiff at London Road, a streak that has seen them go winless since October 1986.
Peterborough's reward for a battling display is to climb out of the Championship bottom three, above Wolverhampton Wanderers courtesy of goals scored.
Leaders Cardiff, meanwhile, need 14 points from their remaining eight games to secure promotion to the Premier League and must regroup for Monday's clash at home to Blackburn Rovers.
The Bluebirds were forced on the defensive at the start as Posh went close through Gayle, whose shot from 18 yards was well held by Cardiff goalkeeper Marshall - making his 300th club career start.
Cardiff made their presence felt when Peter Whittingham tried his luck from the edge of the penalty area, but Robert Olejnik was well positioned in the Posh goal.
The Peterborough stopper was given little chance on 23 minutes when the visitors won a corner, Turner drifting to the front post to cause consternation in the Posh defence and Gunnarsson getting the final touch for his eighth goal of the campaign.
Posh pressed after the break and Kane Ferdinand's header brought a fine stop from Marshall, while Craig Alcock fired over the crossbar from 12 yards.
But Cardiff handed Posh the equaliser when Cowie lost possession as he retreated towards his own box.
The Scotland midfielder rushed back in an effort to make amends but compounded his mistake with an over-eager lunge on Little.
McCann - who had only entered the action two minutes earlier as a replacement for Ferdinand - showed few signs of nerves when he blasted home from the spot.
It was no more than Darren Ferguson's side deserved and it got even better for the hosts seven minutes later when Connolly fouled Gayle in the box and McCann again converted the penalty.
Rudy Gestede had two good, late chance to rescue a point for Cardiff but Peterborough held on to claim a crucial three points.
Peterborough manager Darren Ferguson:
"I wouldn't want anyone else other than Grant McCann standing over a penalty. He has a terrific record and put them both away superbly.
"We have beaten a team that is bound for the Premier League twice - and we have done it on merit on both occasions.
"Hopefully it turns out to be a big win for us. I'm not fussed about our league position because it is points that matter to me.
"March has always been a good month for us and that has certainly been the case again."
Cardiff City manager Malky Mackay:
"We've looked at the first penalty again and it's never been a penalty, Don [Cowie] actually kicks the ball and doesn't touch the guy at all.
"The boy has fallen over and the referee has fallen for the crowd shouting again, like they had been and we warned them at half-time. It's a real poor, poor decision.
"We're disappointed in our own defending roundabout both of the penalties because we caused our own problems to allow the referee the chance to give them.
"Because other than that they weren't near a goal the whole game; it was a scrappy game, the pitch was very hard and you could see that for both teams with wayward shots when the 'bobble' hits."