Philippe Coutinho’s first-half goal and Gerrard’s 87th-minute effort, allied to results elsewhere, mean QPR are likely to make an instant return to the Championship even if they win their final three games.
Chris Ramsey’s side, who levelled through Leroy Fer and had Nedum Onuoha sent off for two bookable offences, are now eight points from safety.
The victory was Liverpool’s first in four matches and eased some of the pressure that has been growing around manager Brendan Rodgers, who has seen his side’s hopes of Champions League qualification evaporate.
Rodgers is confident that he will be given further time and support by the club’s owners, the Fenway Sports Group, to continue re-building next season.
But he needs a positive end to the season to support his case and, not for the first time, he was left indebted to Los Angeles Galaxy-bound captain Gerrard, who was playing in his penultimate home game.
The game started on a sombre note, with both sides wearing black armbands as a mark of respect for the wife of QPR defender Rio Ferdinand, Rebecca Ellison, who died from cancer at the age of 34 on Friday evening.
Former England international Ferdinand has not played a prominent role this season, with the last of his 11 league appearances coming almost two months ago.
But he remains an influential squad member and his personal loss must have been felt by his team-mates ahead of a match from which they needed to get some reward.
History was not on their side, with QPR’s only ever win at Liverpool having come back in 1991.
– Plane protest –
Rodgers had to witness a plane flying over Anfield at kick-off carrying a banner calling for his dismissal and the reinstatement of former manager Rafael Benitez, and on the pitch his side made a nervy start.
QPR, with only two wins in their last 17 games, went close through Steven Caulker’s volley following a corner and a long-range shot from Fer that goalkeeper Simon Mignolet turned around a post.
But calmness was restored 19 minutes in when Liverpool went in front with a ruthless strike.
Caulker’s error just inside his own half was punished as Raheem Sterling fed Rickie Lambert to cross low for Coutinho, who took a touch before curling his eighth goal of the season in off the crossbar.
Liverpool threatened to take complete control, but could not find the second goal that would have killed off QPR’s hopes and were guilty of two appalling misses in the opening 10 minutes of the second half.
Adam Lallana shot wide with just Rob Green to beat, but that was surpassed when Sterling somehow failed to hit the target from inside the six-yard box following a sublime pass from Jordan Henderson.
Green then saved from Gerrard and Dejan Lovren, and Liverpool were made to pay for their wastefulness when Fer volleyed in an equaliser from a Joey Barton corner.
With 11 minutes to go Liverpool had the perfect chance to make amends, but after Onuoha had pulled back Martin Skrtel, Gerrard saw his weak spot-kick saved by Green.
But Onuoha was then sent off after scything down Sterling and Gerrard proved that he is made of stern stuff when he headed in Coutinho’s corner before departing to a standing ovation.