The hosts dominated for an hour on Sunday, as Leroy Fer twice hit the crossbar and Charlie Austin and Sandro also went close.
However, the deadlock was broken by Richard Dunne scoring his 10th Premier League own goal after quick thinking from Raheem Sterling and Glen Johnson at a free-kick.
Eduardo Vargas levelled for the hosts in the 87th minute, but that was only the start of the amazing late drama.
Philippe Coutinho raced up the other end to score and then Vargas headed in his second equaliser, before the match was settled by another bizarre twist.
Sterling sprinted in behind the QPR defence on the break and pulled a pass back in search of Mario Balotelli, only for Steven Caulker to turn the ball into his own net when trying to intercept.
"I'm still in shock," Gerrard told Sky Sports. "We were very lucky and would have had no complaints if we'd come away with nothing.
"It was a very stop-start performance but what I will say is that we hung in there and got the win."
Sterling had endured a difficult week after coming under the spotlight for feeling tired while on international duty with England and he was just glad to get back to playing football.
"We weren't at our best but we hung in there to get the three points we didn't deserve and that's football," added the 19-year-old winger.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.