Wells' winner was totally against the run of play, as was Chris Martin's opening goal a minute before the interval.
Sam McCallum's second-half equaliser - his second goal in as many games - appeared to have earned a point for Rangers, who were pushing for a second goal when they were hit with a classic sucker punch.
City broke forward and Andreas Weimann set up Wells, who had two loan spells at QPR before his move to the west country. The striker, who had not scored in his previous seven appearances, calmly steered the ball beyond keeper Seny Dieng.
Rangers had created a number of chances, with Lyndon Dykes heading Willock's left-wing cross against the post and Moses Odubajo heading wide at the far post after being found by Yoann Barbet.
City's Daniel Bentley was by far the busier keeper in what was a one-sided first half before Martin's goal.
Bentley denied Andre Gray after the on-loan Watford striker had turned away from Tomas Kalas, and he also pushed over a shot from Stefan Johansen.
This was QPR's 100th league match under Mark Warburton and although they have made significant progress during his time as manager, falling behind after failing to take chances has been a regular theme of his tenure.
It was the case in midweek at Bournemouth, where they suffered their first defeat of the season, and again on this occasion.
The Robins counter-attacked after Moses Odubajo had given the ball away. Han-Noah Massengo evaded Jordy de Wijs on the left and sent in a low cross towards Andreas Weimann, who held off Rob Dickie and laid the ball back for Martin to tuck away his third goal of the season.
The hosts finally found the net nine minutes into the second half at the Kiyan Prince Foundation Stadium when Chris Willock's dangerous left-wing cross was headed away by Rob Atkinson but only as far as McCallum, who thumped home from 18 yards out with his less-favoured right foot.
They then put City under major pressure as they searched in vain for a second goal. Bentley gathered a long-range effort from Barbet, twice denied Dykes at point-blank range and similarly prevented substitute Charlie Austin putting QPR ahead after the striker was put through on goal.
Bentley was also grateful to see strikes from Willock and Barbet flash narrowly wide as Rangers continued to dominate.
And in injury time Bentley was called into action twice more, diving to his right to keep out Willock's shot and saving at his near post from Johansen.
They proved to be crucial stops as Wells had the final say.