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.