Alex Gordon hit a three-run homer with two outs in the bottom of the ninth and the Kansas City Royals rallied for a 7-5 victory over the Baltimore Orioles on Friday night to snap a five-game losing streak.

Orioles closer Alfredo Simon (2-2) retired the first two batters in the ninth before walking Rick Ankiel and giving up a single to Wilson Betemit. Gordon’s second home run of the season landed in the Royals bullpen.

It was the Royals’ first walk-off home run since David DeJesus on July 12, 2008, against Seattle.

Blake Wood (1-2), who worked the ninth, picked up his first major league victory.

Ty Wigginton went 3 for 4 with two RBI-doubles for the Orioles, who scored two runs in the top of the ninth to take a 5-4 lead. Nick Markakis led off the Baltimore ninth with a single and scored from first on Wigginton’s double to right-center. Wigginton stopped at third on Luke Scott’s single.

Adam Jones hit a bouncer to Betemit at third, who fumbled it, allowing Wigginton to score, giving the Orioles a 5-4 lead.

The Royals took a 3-0 lead in the first. Betemit had a two-run single and Ankiel doubled home Jason Kendall.

Jones walked to lead off the Orioles second, stole second and advanced to third on catcher Kendall's throwing error. He scored on Felix Pie's sacrifice fly and Wigginton doubled home Markakis in the third to cut the lead to 3-2.

The Orioles tied it in the sixth, when Markakis led off with a walk, took third on Wigginton's single and scored on Scott’s sacrifice fly.

The Royals regained the lead in the bottom of the inning when Mitch Maier’s double scored Yuniesky Betancourt, who began the inning with a single.

Right-hander Sean O’Sullivan, making his second Royals start since being acquired in a July 22 trade with the Los Angeles Angels, allowed three runs, four hits and two walks in six innings.

Orioles rookie starter Jake Arrieta was pulled after 4 1-3 innings, giving up three runs, six hits and five walks.

Notes: IF Josh Bell worked out with the Orioles on Friday, but could not be officially added to the 25-man roster before Saturday. He was optioned July 21 to Triple-A Norfolk and must stay off the big league roster for 10 days. He will take the roster spot of IF Miguel Tejeda, who was traded Thursday to San Diego, for minor league pitcher Wynn Pelzer. Royals DH Jose Guillen led off the fifth with a double, the 300th of his career.