Cardiff City academy graduates Isaak Davies and Rubin Colwill scored as the Bluebirds produced a comeback to dent Queen's Park Rangers' promotion hopes.
Andre Gray smashed home his first goal at Loftus Road this season to give the hosts a deserved lead at half-time.
QPR failed to score a second and Isaak Davies equalised as his shot beat ex-Cardiff goalkeeper David Marshall.
The visitors took the lead five minutes later as Rubin Colwill scored with a superb free-kick from 20 yards.
The win all-but secures Championship football for Cardiff next season, while delivering a serious blow to QPR's hopes of automatic promotion.
QPR remain fifth and inside the Championship play-off places after the defeat, but failed to make ground on their promotion rivals, while Cardiff rise to 17th and are now 18 points clear of the relegation zone.
Illnesses meant Mark Warburton was forced to make changes to the QPR side beaten at promotion rivals Blackburn Rovers with Gray and Lee Wallace recalled.
Cardiff boss Steve Morison, who was taking charge of the Bluebirds for the first time since he was confirmed as manager on a permanent basis, made three changes to the side that beat Derby County 1-0 in midweek as he opted to rotate his players.
The Bluebirds look increasingly safe from relegation trouble with Cardiff boss Morison already planning for next season, so there was little pressure on the visitors as they looked to disrupt the hosts' promotion plans.
They almost took a lead inside 10 minutes as the recalled Colwill fed Jordan Hugill whose effort was brilliantly saved by former Cardiff goalkeeper David Marshall.
Gray, whose five previous goals this season had all come on the road, tested Alex Smithies as he poked towards goal on 15 minutes, but the goalkeeper saved at his near post.
The hosts were enjoying plenty of possession and they opened the scoring on 38 minutes thanks to Moses Odubajo's fine run and cross which Perry Ng failed to clear, allowing Gray to slam home from inside the area.
The goal rocked Cardiff who were dissected by a QPR break two minutes later, but Smithies saved his side as he held Wallace's effort after Ilias Chair found him in space.
The visitors created a decent opportunity early in the second half when Will Vaulks' ball over the top caused QPR concern, but Hugill stalled and then shot over when he had the chance to run clear.
Chair and Colwill exchanged shots over the crossbar before Gray missed an excellent chance to double QPR's lead on 66 minutes after Chris Willock's run and pass completely exposed Cardiff.
That moment proved pivotal as four minutes later Cardiff substitute Isaak Davies cut in from the left and shot, Marshall was able to get a hand to the ball but not prevent it going over the line.
Cardiff's away fans were cheering again on 74 minutes as Colwill scored with a superbly struck free-kick after Rob Dickie's foul gave him the chance from around 20-yards out.
The goals stunned the hosts who never recovered with Cardiff threatening to add a third as sub - and another academy product - Joel Bagan saw one effort saved by Marshall and one shot fired off target.
Queens Park Rangers: Marshall, Dickie, Dunne, Barbet, Wallace (Adomah 81'), Odubajo, Field (Dozzell 85'), Hendrick, Willock (Amos 81'), Chair, Gray.
Subs not used: Mahoney, Kakay, Ball, McCallum.
Cardiff City: Smithies, Drameh, Ng, Flint, McGuinness, Doughty (Bagan 56'), Wintle, Vaulks (Davies 56'), Ralls, Colwill, Hugill (Ikpeazu 82').
Subs not used: Phillips, Denham, Pack, King.