Dexter Blackstock put paid to Cardiff's play-off ambitions as QPR notched up a win that guarantees their Championship survival.
There was delirium in the stands as the final whistle sounded and pandemonium on the pitch.
The frustration of a disappointing season boiled over as Michael Chopra's shove on Lee Camp saw the Cardiff striker dismissed for a second bookable offence.
Chopra's dismissal sounded a sour final note to an entertaining game, but nothing could take the shine off the Rangers' celebrations once it emerged that Blackstock's 14th goal of the season - combined with favourable results elsewhere - had ensured the home side's safety.
Rangers were good value for the win, staging an impressive performance after a lively opening that saw both sides squander decent opportunities.
With the game only a minute old, Chopra's curling free-kick had the diving Camp beaten but strayed just wide of the left-hand upright.
Five minutes later, Marc Nygaard should have scored with the goal at his mercy but, perhaps fearing he had strayed offside, passed to Steve Lomas, whose shot was cleared off the line by Cardiff defender Roger Johnson.
But Rangers, full of verve and energy, clearly had the visitors on the back foot and with 23 minutes gone their enterprise was rewarded with the opening goal.
Lee Cook, returning from three games out following a knee injury sustained at Preston, whipped in a cross from the right for Blackstock and the big frontman rose to nod home the winner with an angled header.
With half-time beckoning, Cardiff almost regained a foothold in the game with Stephen McPhail putting Willo Flood through on the right only for Steven Thompson to hit a clean-air shot.
Cardiff came back strongly in the second half, but clear-cut chances were at a premium and Rangers clung on for a victory that will linger long in the memory of the Loftus Road faithful.