Updated

Philadelphia, PA (SportsNetwork.com) - Cole Hamels fired seven solid innings to lead the Philadelphia Phillies to a 3-2 win over the Pittsburgh Pirates on Wednesday.

After he allowed two runs in the fifth inning, Hamels (3-3) retired the last seven batters he faced and finished with nine strikeouts over his seven frames.

The Phillies also scored all of their runs in the fifth, capped off by Freddy Galvis' two-out hit that scored Carlos Ruiz.

"Total team effort," said Phillies manager Ryne Sandberg. "Hamels was outstanding, and the offense bounced back for three runs after we went down two."

Francisco Liriano (1-3) took the loss despite seven good innings that saw him allow three runs on seven hits and three walks with six strikeouts. Andrew McCutchen's single scored both Pittsburgh runs.

The Pirates were poised to tie the game in the ninth when Jonathan Papelbon's throwing error moved pinch-runner Steve Lombardozzi to third base with one out. Lombardozzi tagged from third on Jordy Mercer's flyout to right field, but Jeff Francoeur's strong throw beat him to the plate and allowed Ruiz to apply the game-ending tag.

"I think it's an aggressive play and it's a play we had a chance to score a run on," said Pirates manager Clint Hurdle. "That's the thing. He's going to the wall and he's trying to catch a ball at the wall and then come off and make a throw. He made an excellent throw."

Each starter scattered a few baserunners through the first four innings before the Pirates struck first. With the bases loaded and one out, Hamels moved a step closer to escaping the jam by striking out Sean Rodriguez, but McCutchen lined the first pitch of his at-bat into center field to plate two runs.

That lead, though, was short-lived. Francoeur and Cesar Hernandez opened the home half of the fifth with singles, and Ruiz doubled Francoeur home to cut the deficit in half. Liriano struck out Hamels, but Ben Revere's run-scoring groundout evened the score. The Phillies then went in front when Ruiz scored on Galvis' single.

Game Notes

Papelbon passed Jose Mesa for first place on Philadelphia's all-time saves list with 113 ... The Phillies had not scored four runs with Hamels on the mound since Sep. 17, 2014 ... Philadelphia looks for a series split Thursday with Aaron Harang on the bump. He will be opposed by former Phillie Vance Worley.