PITTSBURGH — Gerrit Cole's frustration of no longer being perfect was still evident nearly a half-hour after the game ended.

After finishing a post-game interview, the rookie right-hander walked toward the shower room and slapped one of his socks against the fish tank that sits on the middle of the Pittsburgh Pirates' clubhouse.

Cole Hamels looked more like a former World Series MVP on Thursday as he pitched seven strong innings, Carlos Ruiz hit a tiebreaking single and the Phillies beat Cole and the Pirates 6-4 Thursday.

Cole (4-1) lost for the first time in the majors after becoming the first Pirates pitcher to win his first four career starts since Nick Maddox in 1907. Cole allowed three runs and eight hits in 5 1-3 innings.

"I thought he pitched well," Pittsburgh manager Clint Hurdle said. "He's a 22-year-old young man. He's still learning, continuing to grow. He's fun to watch."

Cole took a 2-0 lead into the fifth inning but the Phillies halved their deficit on Ben Revere's single. Cole was then chased during a five-run sixth that put Philadelphia ahead for good, 5-2.

Cole was removed after Ryan Howard walked with one out and Domonic Brown followed with a single.

Both teams complained about home plate umpire Chris Conroy's strike zone and Cole seemed particularly upset after the walk to Howard, though he stopped short of being critical when asked about some close calls during that at-bat.

"I made a couple of pitches on the black (of the plate) but those pitches can go either way depending on the judgment,' Cole said. "I felt I made a couple of quality pitches."

Vin Mazzaro, who had not allowed any of his 12 inherited runners to score this season, came on and gave up three straight singles. Delmon Young's hit loaded the bases and Kevin Frandsen's single tied it before Ruiz hit a liner to center to score Brown and Young and put Philadelphia ahead.

Ruiz, who sat out the first 25 games of the season after being suspended by Major League Baseball for testing positive for a banned stimulant, had driven in just four runs all year prior to Thursday.

Revere capped the inning by driving in a run with a grounder.

"The Pirates have a really good bullpen but I think it made a difference when we were able to get Cole out of the game," Phillies manager Charlie Manuel said. "He's a good pitcher now and he's going to be a real good pitcher. He was tough."

Cole felt his inability to control the count was the biggest reason he lost.

"The difference was working ahead or working behind in the count," Cole said. "When I got ahead, I was able to get outs. When I fell behind, their hitters were able to leverage that and get hits."

Hamels (3-11) gave up one earned run and five hits, striking out eight without a walk. He won for the first time since June 5.

"It was being able to get back to what I know, which is establish the strike zone early then throw all my pitches," Hamels said. "Ultimately, it was staying down in the zone. That's where I've got hurt in the past, I get guys where I want them and not able to finish them off because I'm getting too many balls up in the zone."

Starling Marte and Jose Tabata each had two hits for Pittsburgh, which has the best record in the majors, but has lost two of three since a nine-game winning streak. Marte ran his hitting streak to nine games.

Hamels received some rare support as the Phillies have scored just 22 runs in his 11 losses.

Revere had three of the Phillies' 13 hits and two RBIs. Ruiz, Jimmy Rollins and Young each had two hits.

Jonathan Papelbon worked a perfect ninth inning for his 17th save in 21 opportunities.

Pinch-hitter Michael Young's sacrifice fly in the eighth extended the Phillies' lead to 6-2.

The Pirates scored twice in the eighth on a pinch-hit RBI single by Garrett Jones and a double-play grounder by Andrew McCutchen.

McCutchen's two-run double in the third opened the scoring.

Philadelphia won for just the 10th time in 25 games as it avoided dropping to a season-worst six games below .500. The Phillies won a series in Pittsburgh for the first time since 2008.

NOTES: Pittsburgh RHP A.J. Burnett is likely to come off the disabled list Sunday and start against the Cubs at Chicago, though Pirates manager Clint Hurdle would prefer the veteran make one minor league rehab start. Burnett, who has been out since June 9 with a strained right calf, insists he does not need to go on a rehab assignment. ... Pirates SS Jordy Mercer got the day off after going 1 for 9 in the first two games of the series and making an error on Wednesday night that allowed a run to score. ... The Pirates open their three-game series with the Cubs on Friday with LHP Francisco Liriano (7-3, 2.23) pitching against RHP Jeff Samardzija (5-7, 3.34)