Karlan Grant and Ike Ugbo both scored in stoppage time as Cardiff snatched a dramatic 2-1 victory at 10-man Preston.
Grant bundled the ball over the line in the 96th-minute to equalise, before Ugbo’s excellent glancing header three minutes later sparked pandemonium in the away end.
Milutin Osmajić’s 48th-minute goal put Preston ahead but the hosts were on the backfoot for much of the second half owing to Robbie Brady’s red card.
The midfielder was shown a second yellow just four minutes after Osmajić’s goal but Preston did brilliantly to keep Cardiff at bay, only to see their hard work undone in the final minutes.
The result moved Cardiff up to sixth in the table, just a place and a point behind Preston.
The visitors carved out the better chances in a scrappy opening 45 minutes, with Preston goalkeeper Freddie Woodman called into action to deny Bluebirds duo Manolis Siopis and Perry Ng.
Woodman continued to be the key player once again for Preston before the break, as the hosts’ No 1 produced a diving stop to keep out an angled strike from former Lilywhites star Callum Robinson.
However, despite struggling to make any inroads in the opening period, the contest turned on its head after a bizarre moment on 48 minutes, as Osmajic prodded home the breakthrough.
Mark McGuinness’ loose touch presented the Montenegro international with a chance to race in behind the visitors’ defence and he kept his cool to steer the ball past Runar Runarsson.
Despite looking well placed to seize the initiative from Osmajic’s strike, Preston’s positivity was quickly checked just four minutes later, as veteran winger Brady was shown a second yellow card after clipping Yakou Meite in midfield.
Brady’s sending-off completely changed the tempo of the game for Preston in the final half hour as manager Ryan Lowe rotated his side to try to dig in for the win.
With a player advantage in the closing stages, Woodman again came to the fore for Preston, to deny Meite from distance.
As Cardiff continued to probe, Grant conjured up a brilliant opening, with his rasping drive getting the better of Woodman, before clipping the outside of the post.
Cardiff boss Erol Bulut threw on a flurry of attacking substitutes in the final 20 minutes to try to force an equaliser, and the changes eventually wrested the contest away from Preston.
Pinball inside the Preston box, deep into nine minutes of added time, allowed Grant the chance to level with a scuffed effort, before Ugbo got away from his marker at a corner to win the match in the 99th minute.