BALTIMORE -- Yankees manager Joe Girardi has said several times over the past week that he likes how his team has fought through injuries and adversity this season.
New York once again found a way to win Thursday in Baltimore to continue its late-season surge toward the playoffs.
The Yankees scored the go-ahead run in the ninth inning on a wild pitch by Orioles closer Jim Johnson, and New York earned a 6-5 victory Thursday to take three of four games in the crucial series.
The win was especially big for the Yankees because the teams entered the night with their season series even at nine. As a result, if the two are tied for the wild card at the end of the season, the play-in game would be held at Yankee Stadium.
"We need to continue to win and we need to continue to take series if we want to play in October," Girardi said. "A lot of good performances by people tonight. (Johnson) threw a ball away and then the wild pitch. It was the difference."
Mark Reynolds, facing his former team, hit his 19th homer of the season and second in the series. It was also the 200th home run of his career. Curtis Granderson hit his sixth homer for New York.
Johnson entered in the ninth and allowed a leadoff single to Brendan Ryan. Chris Stewart bunted, and Johnson (3-8) sailed his throw into center field, leaving runners at first and second. A sacrifice bunt by Granderson set up the decisive wild pitch.
"Every loss is frustrating," Johnson said. "We've been in them and haven't gotten the big pitch or the big hit or whatever it needs to be. But we're in every game. We're running out of time, but we need to start putting a couple key pieces together. The series is over, and we have got to focus on our next series now."
Nick Markakis hit his 10th home run of the season for Baltimore. Danny Valencia added his eighth homer, a three-run shot off David Robertson that tied the game in the eighth inning.
"It was a tough outing," said Robertson, who allowed three hits with two strikeouts. "I just couldn't make enough pitches. I left too many pitches in the middle of the plate. I struggled."
Mariano Rivera (6-2) was credited with the win after pitching a 1-2-3 ninth inning. Robertson would have been in line for the victory, but the official scorer chose not to give him credit because he pitched briefly and ineffectively.
Orioles starter Wei-Yin Chen overcame a shaky start, giving up five runs on seven hits and tying a career high with nine strikeouts over 6 1/3 innings. Chen allowed the Yankees to go 6-for-15 with a double and a home run in the first three innings, but he then retired 13 consecutive batters before allowing the homer to Granderson in the seventh that gave New York a 5-1 lead.
Yankees starter Phil Hughes was replaced by David Huff after three innings and 50 pitches. Hughes gave up one run and three hits with three strikeouts. He also had two wild pitches and left with a three-run lead.
Huff threw 3 1/3 innings, allowing one run on two hits with a strikeout.
"I was just trying to be aggressive and throw first-pitch strikes," Huff said. "I was trying to get ahead of guys. I did not want to start nibbling or being too fine. We're definitely trying to win ballgames and to be playing in October."
The Yankees opened the scoring in the second on a two-run homer by Reynolds that was scorched over the left-field fence. It was the eighth homer allowed by Chen in his past six starts.
New York increased the lead to 4-0 in the third on a two-run single by Vernon Wells.
Manny Machado put the Orioles on the board in the bottom of the third with a single that scored Matt Wieters.
NOTES: The game was delayed one hour and 18 minutes because of thunderstorms in the area. ... Yankees CF Brett Gardner left the game after the first inning with a left oblique strain and was replaced by Granderson. ... The Orioles honored Rivera before the game with a bronze sculpture of a broken bat. Baltimore manager Buck Showalter joked in his pregame press conference that, "I'd like to give him a blown save tonight." ... Orioles RHP Bud Norris was originally scheduled to start Friday in Toronto but was scratched for the series because of elbow soreness.