The Bluebirds had won all 10 league matches at the Cardiff City Stadium this season but were stunned by a Posh side who had failed to win in eight.
Michael Bostwick put the struggling visitors ahead after 22 minutes with a superb long-range effort and on-loan Dagenham striker Dwight Gayle netted the second two minutes after the interval.
Rudy Gestede's late goal ensured a nervy finish for Darren Ferguson's team, but they held on for three crucial points.
The result saw Cardiff's lead at the summit reduced to two points, while Peterborough climbed off the bottom for a couple of hours until Sheffield Wednesday's win at Barnsley.
The hosts thought they had taken the lead after just four minutes when Heidar Helguson headed home from Craig Bellamy's free-kick, but it was ruled out for offside.
Peterborough twice went close through George Boyd and Cardiff failed to heed the warnings, falling behind midway through the half. Posh capitalised on the dubious award of a free-kick, Boyd rolling it to Bostwick, who rifled in from 20 yards.
Bellamy attempted to muster an immediate response but after expertly controlling a loose ball on the edge of the box, he pulled his effort just wide.
The Welshman threatened again soon after, latching onto Craig Conway's superb pass before cutting the ball back for Craig Noone, who could only find the gloves of Robert Olejnik with his shot.
But having failed to make the most of their dominance in the latter stages of the first half, the hosts fell behind early in the second. Lee Tomlin fed Gayle and he raced through, slotting coolly past David Marshall to make it four goals in three matches and the first time this season Cardiff have conceded more than one goal in their own backyard.
Gayle was afforded space to try and double his tally after 63 minutes but his low powerful shot was tipped wide by Marshall.
Helguson later outmuscled Gabriel Zakuani to carve out a shooting opportunity, only to hook just wide from inside the box.
Gayle should have put the game beyond doubt but somehow contrived to fire straight at Marshall from four yards, and Cardiff ensured a tense finish for the visitors when Gestede turned in Ben Turner's flick on.
But, despite six minutes of stoppage time, there was to be no sting in the tail.