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.
Preston: Rudd; Fisher (Gallagher 77), Bauer, Davies, Hughes; Pearson, Browne, Johnson (Potts 85); Barkhuizen (Maguire 71), Stockley, Sinclair (Nugent 85)
Subs: Ripley, Huntington, Ledson, Harrop, Bodin.
Cardiff City: Smithies; Sanderson, Morrison, Nelson, Bennett; Adomah (Mendez-Laing), Vaulks, Bacuna, Ralls (Tomlin 77), Hoilett (Pack 90+5); Paterson (Glatzel 65)
Subs: Etheridge, Flint, Smith, Whyte, Ward
Referee: Oliver Langford