Cardiff struck three times in the final 21 minutes to win their Sky Bet Championship play-off battle with Preston 3-1 at a rain-lashed Deepdale.
A drab contest played out in ferocious showers burst into life when Joe Ralls broke the deadlock with a far-post header in the 69th minute.
Daniel Johnson quickly equalised but Nathaniel Mendez-Laing and Robert Glatzel struck late on to lift the Bluebirds above Preston and into the top six.
The dramatic finish was out of keeping with much of what had gone before. With Preston above Cardiff on goal difference going into the game, both sides realised there was plenty at stake.
Chances were few and far between in a goalless first half.
Tom Barkhuizen had an early opening for Preston but flashed a shot wide and Scott Sinclair had an opening blocked off by Curtis Nelson after a mistake from Dion Sanderson.
Cardiff's Albert Adomah fired an effort wide and Junior Hoilett also missed the target at the second attempt after his initial shot was blocked.
Sinclair had another shot blocked by Sean Morrison, who then headed over from a corner at the other end shortly before the break.
It was not until the 56th minute that either goalkeeper was seriously tested, but Cardiff's Alex Smithies was alert, producing a fine save to his right to turn away a low drive from Sinclair.
That ignited the contest and Ralls tested Declan Rudd in the Preston goal after a driving run.
Ralls went better shortly afterwards, opening the scoring with a close-range header.
Preston failed to clear after Hoilett fired a free-kick into the wall and Ralls headed home after Sanderson clipped the ball into the box from the right.
The Bluebirds could have increased their lead immediately but Hoilett blasted over and Preston responded to level just four minutes after falling behind.
Substitute Sean Maguire created the opening when he played in Alan Browne. The captain's strike was blocked but Johnson was on hand to tuck away the rebound.
Neither side were content to settle for a draw and Preston had a chance to take the lead when Jayden Stockley headed over.
Cardiff hit back again, though, and Mendez-Laing struck the decisive blow eight minutes from time when he raced onto a Lee Tomlin pass and slotted past Rudd.
Preston pressed for another equaliser but Andrew Hughes headed straight at Smithies and David Nugent curled wide in heavy rain in the closing stages.
Glatzel ended the contest when his stoppage-time strike was deflected past Rudd.
What the managers said...
Preston's Alex Neil: "I don't think there was a lot in the game. I think the biggest frustration was that we found ourselves in good areas but didn't make the most of the opportunities. We were wasteful. They tended to score from their opportunities. Ours were more off-target.
"Their second goal was really poor defending from our part. We should be tight, stop him playing, stop them playing that pass for Mendez-Laing to run through. Even then we should take a foul, bring him down and take a booking, stop the game. But we don't."
Cardiff's Neil Harris: "It's a huge win for us. We felt it was really vital that we followed up the performance and result against Leeds with another solid one today. It's a big confidence boost for us and pushes us in the right direction.
"What pleased me most was the character. When you are 1-0 up away from home you want to see it out. To bounce back, like we did after they equalised so quickly, and go on score two more goals is testament to my players' character."