Ansarifard applied the finish to a lovely move 10 minutes into the second half.
After neat build-up play involving Joe Lolley, Matty Cash and Joao Carvalho, Ansarifard slotted home only this third goal since joining Forest in November.
The home side were given a chance to equalise with three minutes remaining when former Rangers defender Jack Robinson was adjudged to have handled Josh Scowen's corner while challenging Matt Smith in the air.
But Wells, on as a substitute, saw his spot-kick pushed away by Pantilimon.
Ansarifard would have scored seven minutes before the interval but for a combination of Joe Lumley and the woodwork.
Rangers were opened up by a clever pass from the outstanding Lolley, who sent Ansarifard through on goal.
Keeper Lumley used his legs to deflect the Iranian forward's shot on to the underside of the bar and then reacted quickly to grab the loose ball as Ansarifard attempted to follow up.
QPR had made much of the early running, with Darnell Furlong heading wide from Scowen's corner and Geoff Cameron heading over a free-kick from Ryan Manning, who later curled a free-kick wide.
As Rangers continued to threaten in the first half, Pantilimon held Tomer Hemed's ambitious overhead kick and an effort from Ebere Eze.
After Ansarifard's goal, Pantilimon twice denied Hemed, keeping out a low shot and a far-post header from the on-loan Brighton man.
Pantilimon also blocked a powerful strike from Eze and saw Massimo Luongo's long-range shot flash narrowly wide.
It was the 11th home league defeat of a miserable season for QPR, who have won just twice since Boxing Day.
They face a difficult summer of cost-cutting as Financial Fair Play restrictions continue to bite.
Their new manager will be expected to work with a tight budget and develop youngsters as the club look to balance the books.
Caretaker boss John Eustace, placed in charge following last month's sacking of Steve McClaren, included both Eze and Bright Osayi-Samuel – two players Rangers have high hopes for.
And there was a full senior debut for Lewis Walker against the club the 20-year-old forward's father Des made his name with as a player.
Walker worked hard up front before being substituted in the second half.
He was replaced by another youngster, winger Olamide Shodipo, who was also lively.
Wells, on the other hand, twice blasted well over after coming on – and then failed to take Rangers' big chance to rescue a point.