Peterborough moved off the bottom of the Championship with a deserved win to end leaders Cardiff's perfect home record.
Michael Bostwick gave Peterborough a first-half lead when his powerful free-kick left David Marshall with no chance.
The visitors doubled their lead early in the second half when Dwight Gayle finished off a counter-attacking move.
Rudy Gestede pulled a goal back but it was too little, too late for Cardiff.
Despite the defeat and an end to their 100% home record, Malky Mackay's side remain top after Crystal Palace drew 2-2 at Birmingham
The sides were separated by 31 points and 23 places at the start of the afternoon and Peterborough had picked up only one point from their previous eight games.
Players and supporters took part in a minute's applause prior to kick-off in memory of former Cardiff City owner Rick Wright, following his death at the age of 81.
Cardiff made a good start to the game and although they had the ball in the back of the net after four minutes, Heidar Helguson's header from Craig Bellamy's free-kick was ruled out for offside.
Goalkeeper David Marshall was called into action for the first time to deny George Boyd and the midfielder's deflected shot was then acrobatically cleared off the line by Ben Turner.
Having survived those scares it was under controversial circumstances that Cardiff fell behind on 22 minutes.
Referee David Coote penalised Helguson and awarded a free-kick on the edge of the penalty area to the visitors despite Cardiff protestations they should have been given the decision.
And their sense of injustice was compounded when from the resultant free-kick, Boyd rolled the ball to Bostwick, who fired an unstoppable shot which left Marshall with no chance
After the shock of conceding, Cardiff rallied and Bostwick cleared a Bellamy header off the line before Craig Noone's shot was well gathered by Robert Olejnik.
Despite Cardiff's possession and chances Peterborough's well organised defence held firm and they were worthy of their 1-0 interval lead.
Within two minutes of the restart Cardiff's defence were caught napping and Darren Ferguson's side doubled their advantage.
The impressive Lee Tomlin fed Gayle and the on-loan Dagenham striker raced through, slotting coolly past Marshall.
Peterborough could and should have added to their tally with Gayle's low, powerful shot tipped wide by Marshall.
Cardiff looked out of sorts and Helguson wasted two chances to reduce the deficit while Gayle should have wrapped up the victory for Posh but he fired straight at Marshall.
The home side set up a tense finale when substitute Gestede turned in Turner's flick on with a minute remaining but they could not find another goal despite six minutes of stoppage time.
Defeat means Cardiff's lead at the top of the Championship is reduced to two points, while Peterborough climbed off the bottom ahead of Sheffield Wednesday's visit to Barnsley.
Cardiff manager Malky Mackay:
"There are no easy games in this division and everyone can beat everyone - we are disappointed to lose.
"On another day Heidar (Helguson) could have scored five. We had 20 attempts on goal, did everything but score and weren't clinical. That wasn't good enough.
"We were beaten and can play much better. We want to be as consistent as possible and the league table shows that, but we have to work hard every week.
"We were bound to lose at home at some point, but full credit to Peterborough. They deserved the win."
Peterborough boss Darren Ferguson:
"We have beaten the best team in the league and also won at Hull so that shows we can beat any team in this league.
"It's a very good day. But we haven't been consistent enough this season. I have always believed in the players and maintained the confidence that we can get the job done - but we need to produce consistent performances.
"We played very well but we did so last week. The difference was we defended well too. We stuck to the game plan and deserved the win but we didn't finish them off.
"We were hanging on a bit at the end. But if we continue to perform like that we will be fine in this league."