Everton's Romelu Lukaku (C) scores past Arsenal's goalkeeper Wojciech Szczesny during their English Premier League soccer match at Goodison Park Stadium, Liverpool. (AP Photo)
Victory, in a match where Gerrard struck from the spot either side of Guy Demel's equaliser, left Liverpool two points in front of Chelsea and four ahead of third-placed Manchester City.
However, City have two games in hand over both Liverpool and Chelsea. Liverpool play City at Anfield next weekend.
Gerrard gave the visitors the lead a minute before half-time at Upton Park after James Tomkins handled in the box as Luis Suarez played the ball forward.
But there was still time before the break for the Hammers to grab a disputed equaliser.
It appeared former Liverpool striker Andy Carroll had knocked the ball out of Reds goalkeeper Simon Mignolet's grasp, after shoving a hand in his face, before Demel stabbed home in first-half stoppage-time.
The linesman flagged but, having consulted with his official, referee Anthony Taylor let the goal stand despite furious Liverpool protests.
Taylor was involved in more controversy when he awarded Liverpool a second penalty from which Gerrard made it 2-1 in the 71st minute.
West Ham goalkeeper Adrian came off his line to take the ball but then made contact with Jon Flanagan in his follow-through and Taylor, somewhat harshly, pointed to the spot.
"There were bad decisions both for and against us," said Liverpool manager Brendan Rodgers.
"In all fairness the referee came out after the game and said he got it wrong for their goal."
Frustrated Hammers manager Sam Allardyce added: "Unfortunately we are talking about the officials and not the game.
"There were fouls given by the referee when he was 60 yards away, the second penalty was not a penalty, Adrian plays the ball.
"It looked like Andy Carroll fouled the goalkeeper for our goal but we got it. We don't want that, nobody wants that. We don't have enough quality referees."
Earlier, Liverpool's Merseyside rivals Everton bolstered their hopes of Champions League football next season by moving to within a point of fourth-placed Arsenal after they beat the Gunners 3-0.
Goals from Steven Naismith, Romelu Lukaku and an own-goal by Everton old boy Mikel Arteta saw the Toffees, who have a game in hand over Arsenal, record a convincing victory.
"It was a very good performance," Everton manager Roberto Martinez said.
"The most pleasing aspect had to be the manner in which we defended, our concentration and discipline off the ball," he added.
Dejected Arsenal boss Arsene Wenger conceded his side had showed a "lack of fight" and that the manner of this defeat was a "massive worry" for the north London club.
"Was there a lack of fight? You could say that," said Wenger. "It is a massive worry to lose a game like that."
Naismith gave the home side a 14th minute lead when, after Lukaku's shot was kicked clear by Arsenal goalkeeper Wojciech Szczesny, he side-footed the loose ball into the net.
And 20 minutes later, Martinez's side, knocked out of the FA Cup by Arsenal, doubled their lead.
Lukaku, playing on the wing, collected the ball wide on the right, drove past Nacho Monreal and around Thomas Vermaelen before unleashing a powerful left-footed shot past Szczesny from the edge of the box.
Arsenal, who are now in danger of missing out on a top four finish that would see them into next season's Champions League, tried to respond in the second half.
But Wenger's visitors, whose campaign could hang on the outcome of next weekend's FA Cup semi-final against Wigan, fell further behind in the 62nd minute.
Kevin Mirallas dispossessed Bacary Sagna and sprinted off towards goal before playing in Naismith, who was blocked from rounding Szczesny.
But as the ball came loose Mirallas and Arteta tussled for the ball only for Arteta to get the final touch to divert it into the Gunners' net, with this defeat all but ending Arsenal's slim hopes of winning the Premier League this season.