BALTIMORE - After two Orioles pitchers lost their ability to throw strikes, all but handing the Yankees a three-run fifth inning that gave the Bombers a two-run lead, the question became this:

Could the Yankees' beleaguered pitching staff, particularly a recently under siege bullpen, get the ball to Dellin Betances?

On this Sunday afternoon, the answer was yes.

Though Adam Warren managed to last just 42/3 innings, Chasen Shreve and Justin Wilson combined to form an effective bridge to Betances, who closed the door on a much-needed 5-3 victory over the Orioles in front of 36,343 on a sweaty 91-degree day at Camden Yards.

Betances, in his first opportunity as closer since taking over the job for the injured Andrew Miller, walked Manny Machado with two outs in the ninth but struck out pinch hitter Matt Wieters for his third save of the season.

The victory enabled the Yankees (34-28) to avoid a three-game sweep as they head to Miami for a two-game series against the Marlins that starts Monday night.

With the Orioles (31-31), whose six-game winning streak came to an end, leading 3-2 in the top of the fifth, Baltimore starter Mike Wright walked the bases loaded to start the inning.

Orioles' manager Buck Showalter finally pulled the plug, calling for lefthander Brian Matusz, back from his eight-game suspension for being caught with an illegal substance. Matusz got behind Garrett Jones 3-and-1 before walking the rightfielder to bring in Chase Headley to make it 3-3. The erratic pitcher struck out Stephen Drew and Didi Gregorius but fell behind John Ryan Murphy 2-and-0. He served up an 89-mph fastball that Murphy smacked off the glove of a diving Machado at third for a two-run double that brought in Alex Rodriguez and Mark Teixeira to give the Yankees a 5-3 lead.

Shreve came on with two on and two out in the bottom of the fifth and retired Travis Snider on a soft fly out to left, then pitched a 1-2-3 sixth. After Shreve walked Machado to start the seventh, Girardi brought on Justin Wilson. The lefthander got pinch hitter Delmon Young, struck him out on three pitches, and retired Adam Jones and Chris Davis to end the inning.

The Yankees, as they did in Saturday's loss, scored in the first. Brett Gardner reached on an infield single, trickling one past the pitcher toward the first base side, but Wright retired Headley and A-Rod on fly balls. Teixeira, however, sliced a first-pitch 94-mph fastball down the leftfield line. It kicked up chalk upon landing, for an RBI double that made it 1-0. It was Teixeira's 13th double, tied for team-high, and gave him a team-best 47th RBI.

The Orioles, the case all series, immediately responded, this time against Warren, who allowed three runs and six hits.

Manny Machado started the bottom half with a leadoff single, making him 6-for-10 in the series and 15 for his last 31. Jimmy Paredes struck out and, with Adam Jones at the plate, Machado took off for second. Jones swung at the pitch and punched a grounder through the hole vacated at second by Drew, who went to cover the base, putting runners at the corners. Warren walked Chris Davis to load the bases and Nolan Reimold, 2-for-5 with a triple and a homer Saturday night, lined a 0-and-1 fastball to left-center for a two-run single that made it 2-1. Warren retired Travis Snider and J.J. Hardy to end the 29-pitch inning.

The Yankees responded in the second. Drew blooped a single to center and Gregorius sent a ground shot off Wright for an infield single. Murphy, getting the start for Brian McCann, also reached on an infield single, loading the bases for Mason Williams. The rookie centerfielder, who homered Friday for his first big-league hit, grounded into a 3-2 force play, bringing up Gardner. The leftfielder worked the count full before lining a sacrifice fly to center that brought in Gregorius to tie it at 2-2.

The Orioles took the lead again in the fourth. Reimold led off with a walk and went to second on Hardy's one-out single. Warren struck out Ryan Flaherty, but Caleb Joseph muscled a 2-and-1 fastball, which came in at 92 mph and belt-high, in front of a sliding Jones in right for an RBI double that made it 3-2.