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 ahead of Sheffield Wednesday's visit to 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 began to grow into the game after a nervy start and Tommy Rowe's industry down the left wing created a chance for George Boyd, but his left-footed strike was well held by David Marshall.
They went even closer to breaking the deadlock moments later as Ben Turner was forced to acrobatically clear Boyd's deflected effort off the line.
Cardiff failed to heed the warnings and fell 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 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.
A clearly out-of-sorts Cardiff outfit struggled to mount any meaningful response, though Helguson perhaps should have done better with Bellamy's cross, fluffing wide when well placed.
The Icelandic striker then 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 Turner's flick on.
But, despite six minutes of stoppage time, there was to be no sting in the tail.