The Reds were second best throughout the first half, but took the lead in the 67th minute when QPR defender Richard Dunne bundled the ball into his own net.
Vargas drew the hosts level again moments later, but the match was won in the final seconds of stoppage time when Steven Caulker scored another own goal.
Gerrard conceded that, despite having recorded a win, his team have plenty of room for improvement.
"I'm still in shock to be honest. We are very lucky today," he told Sky Sports News.
"We had no complaints if we came away with nothing [and] we had no complaints if we came away with a point. We are very lucky to come away with three points. Our performance needs to be better in my opinion. It was very bitty."
The three points have moved the Merseysiders up to fifth in the Premier League table.