Lyndon Dykes’ last-minute winner – his fifth goal in as many games and his 11th of the season – took QPR up to eighth in the Championship table.
Albert Adomah exchanged passes with Chris Willock and threaded the ball through to Dykes, who turned and fired home.
Ilias Chair hit the post twice in the first half – on both occasions after being set up by the lively Willock.
First, Chair was surprised Willock’s right-wing cross reached him, and the ball bounced off the Rangers playmaker and against the woodwork.
Then Chair ran on to Willock’s clever pass and his shot went through the legs of keeper Freddie Woodman and struck the same post.
Former QPR man Wayne Routledge also hit the post before interval, in his case with a right-footed strike from near the edge of the six-yard box.
In a cagey second half, Willock had an effort saved by Woodman before Charlie Austin, on as a substitute for the R’s, fired wide.
But as third-placed Swansea faded, the visitors finished strongly and were rewarded by Dykes’ emphatic finish.
It clinched a seventh away win of the season for Rangers, whose clean sheet was their 11th of the campaign.
QPR: Lumley, Dickie, Ball, Barbet, Kakay (Adomah 74), Johansen, Chair (Field 78), Willock, Hamalainen, Thomas (Austin 67), Dykes.
Subs not used: Walsh, Kane, Bettache, Duke-McKenna, Bonne.