NEW YORK, N.Y. - Slumping Carlos Beltran delivered the signature hit of his first season with the New York Yankees, launching a three-run homer with two outs in the ninth inning that beat the Baltimore Orioles 5-3 Friday night.

Beltran has struggled with inconsistency and an elbow injury this year, and the All-Star began the game batting just .221.

But right after Brian McCann lined an RBI single, Beltran hit a drive off Zach Britton (3-1) far over the left-field wall. It was the first time this year that the Yankees won in their final at-bat, and their fourth straight victory overall.

The Yankees struggled with runners in scoring position until the ninth. Brett Gardner led off the inning with a single, then Derek Jeter struck out looking and Jacoby Ellsbury flied out.

Mark Teixeira followed with a walk and McCann singled home a run, setting up Beltran's first walkoff homer since 2008, for the New York Mets.

Britton was already off the field by the time Beltran made it to home plate, where he was mobbed by his teammates.

David Huff (1-0) gave up Steve Pearce's RBI single in the ninth but got the win.

Coming off a decisive three-game sweep of the division-leading Toronto Blue Jays, New York jumped out to a quick lead on Teixeira's RBI double. Then they fizzled, wasting three chances with the bases loaded and failing to capitalize on a career high-tying six walks from Ubaldo Jimenez.

Center fielder Adam Jones threw a runner out at home plate in the second and hit an RBI single in the sixth, helping the Orioles take a 2-1 lead.

Nick Hundley doubled for the Orioles' first hit off Hiroki Kuroda leading off the sixth and scored on Pearce's one-out double.

Pearce had an RBI single in the ninth three batters after third baseman Yangervis Solarte made a fielding error to open the inning.

The Yankees loaded the bases for the first of three times in the second but Beltran, who doubled leading off, tried scoring on Gardner's fly to medium centre field. Jones' throw reached Hundley on one perfect hop, and the catcher had plenty of time to apply the tag for the double play.

Jimenez loaded bases in the fifth with three straight two-out walks. The right-hander has been stung regularly this season in the fifth, giving up 12 of his 41 runs for a 9.26 ERA in that inning. This time he needed one pitch to get out of the jam: Teixeira grounded to first base on the first pitch he saw, keeping it 1-0.

The Yankees loaded the bases again with two outs in the sixth — a single and two walks — but this time Jimenez wasn't given a chance to quash the rally. Manager Buck Showalter hurried out of the dugout following a walk to Solarte and called on T.J. McFarland to face Gardner.

Second baseman Ryan Flaherty got the save, though, ranging deep behind second base to field Gardner's hard one-hopper and making a swift, backhand flip to shortstop J.J.Hardy covering for the forceout.

NOTES: Yankees 2B Brian Roberts singled in the second for his 1,500th career hit. He had 1,452 with the Orioles before signing with New York this off-season. ... Yankees RHP Michael Pineda (60-day, right shoulder muscle) could begin throwing soon. Pineda says he feels good but he had an MRI to make sure the muscle is fully healed before he starts a program, manager Joe Girardi said. ... Showalter said C Matt Wieters (Tommy John surgery) should visit the team in early July. ... The Yankees will honour Tino Martinez with a plaque in Monument Park on Saturday. Martinez played 1B for New York from 1996-2001 and won four World Series titles in that period. ... Up next: Orioles RHP Bud Norris (6-5) goes against Yankees LHP Vidal Nuno (1-3).