George Saville equalised for Boro five minutes into the second half after Pawel Wszolek had given the hosts an early lead.
But on-loan Burnley striker Wells hit back for Rangers to secure their first win in five matches and give boss Steve McClaren a victory to savour against his former club.
Wszolek's fourth-minute goal had given McClaren's side the perfect start.
Jake Bidwell collected Luke Freeman's pass and sent a low cross from the left into the penalty area, where Wszolek scored from close range having drifted in from the right flank.
Boro levelled six minutes into the second half when Ryan Shotton's ball in from the left was headed out by Darnell Furlong as far as former Chelsea youngster Saville, who volleyed home left-footed from near the edge of the penalty area.
Rangers were down to 10 men at the time as they were waiting to replace defender Joel Lynch, who had just limped off injured.
They regrouped and were back in front nine minutes later courtesy of the excellent Wells, whose goal condemned Boro to their first defeat in seven away matches in the Sky Bet Championship.
Wszolek found space on the right and pulled the ball back to the on-loan Burnley striker, who cleverly turned away from Saville, shifting the ball on to his left foot, and smashed his shot past keeper Darren Randolph.
The result was a huge boost for QPR after being dealt a major blow by news that defender Angel Rangel and on-loan duo Geoff Cameron and Tomer Hemed all face lengthy spells of the sidelines because of injury.
Rangers made the early running, with Wells firing wide of the far post before Wszolek's second goal in his past three games and his fifth of the season put them ahead.
And Wells was unlucky not to double the lead before half-time when he superbly wriggled away from Daniel Ayala and shot narrowly wide.
Boro made a determined start to the second half and Saville's fine strike gave keeper Joe Lumley little chance but Wells responded.
Wszolek had a late chance to add a third for Rangers following an error by Shotton.
After Shotton had given the ball away, Josh Scowen burst forward and teed up Wszolek, who blasted wide of the near post.
Boro are now without a win in four matches and have managed to score only three times during the run.
Boss Tony Pulis believes the lack of goals is causing his players to lose focus during matches.
He explained: “Because of the situation with us not scoring goals I think the team is trying their damndest to win a game of football.
“We’re better when we’re solid, and we’ve gone away from that a little bit in respect of trying to chase the goals.
“I think the players have reacted to the fact that we haven’t been scoring goals and in their desperation to score we’ve lost our shape a bit.
“We need a few breaks. We certainly don’t need decisions going against us like they did today.”