BALTIMORE — Standing at the plate with a chance to tie the game, Brett Gardner grounded out to seal a galling defeat to the Baltimore Orioles.

Given the opportunity for redemption, Gardner and the Yankees cranked up the offense to earn a doubleheader split.

Gardner had four hits, homered and drove in three runs to lift New York to a 10-2 victory Monday night.

In the opener, Danny Valencia snapped an 0-for-25 skid with a three-run homer off CC Sabathia, and Baltimore ended a six-game losing streak with a 5-4 victory.

The first game ended with Gardner hitting a bouncer to first base as a pinch hitter with the potential tying run on third base. He returned in the nightcap to torment the Orioles at the plate and in center field, where he made several fine, running catches.

"Game 1 was a close game and I pinch-hit there at the end of the game and wasn't able to come through," Gardner said. "To be able to turn the page and come back and have a good game in the nightcap — have a relatively easy win and save our pitching staff and our bullpen — I thought that was important."

Gardner led off with a single off Jefry Ramirez (0-3) and scored on a double by Didi Gregorius. In the fourth, Gardner hit his seventh homer , a two-run drive that made it 3-0.

That was enough offense for Luis Cessa (1-1), who allowed three hits over six shutout innings.

"Anytime you're coming off a loss, you don't want to lose two," Yankees manager Aaron Boone said. "Gardi set the tone early."

A four-run eighth —highlighted by Austin Romine's two-run homer and an RBI double by Gardner — ended any doubt.

Despite allowing a home run to Tim Beckham, Giovanny Gallegos finished for his first major league save.

New York had a season-high 17 hits, at least one from every starter.

The split left the Yankees a 4-4 record against last-place Baltimore (25-66) and dropped them 2½ games behind first-place Boston in the AL East.

In the first game, the Orioles trailed 4-2 in the sixth when Sabathia (6-4) walked Mark Trumbo and yielded a double to Jonathan Schoop. With the New York bullpen buzzing in an effort to get a reliever ready, Sabathia served up a 2-1 pitch that Valencia drove far over the center-field wall.

"To come through big with the home run there to put us ahead, it feels nice. Can't deny that," Valencia said.

It would be the final pitch for Sabathia, who allowed five runs and seven hits in five-plus innings. The 37-year-old lefty is winless in nine starts against the Orioles since May 4, 2016.

Mike Wright (2-0) struck out four in two innings of relief, Mychal Givens fanned two in the eighth and Zach Britton followed for his second save.

Giancarlo Stanton put the Yankees up 1-0 with his 22nd home run in the second inning. It was 3-0 before Manny Machado doubled and Trumbo connected in the fourth.

The game was a makeup of a rainout on May 31.

TRAINER'S ROOM

Yankees: All-Star reliever Aroldis Chapman (knee tendinitis) left Saturday's game against Toronto with a trainer by his side, but Boone says there has been no discussion about putting the lefty on the DL and that the injury has not impacted his effectiveness. ... C Gary Sanchez (groin) is scheduled to take batting practice on Tuesday in Baltimore, and a decision on the start of his rehab assignment will be made this weekend.

Orioles: Reliever Darren O'Day will undergo surgery Thursday to repair a severe hamstring strain. "I've come to terms with my season being over. I'm excited to get the surgery and kind of get focused on going forward," O'Day said. ... RHP Chris Tillman (back) has been dealing with a callus on his pitching hand but remains on schedule to make his next rehab start.

UP AND DOWN

After going 0 for 4 in the opener of the doubleheader, INF Brandon Drury was optioned by the Yankees to Triple-A Scranton/Wilkes-Barre to make room on the roster for Cessa.

NO TEARS, PLEASE

Dellin Betances is one of the game's hottest relievers, but his run of four All-Star appearances in four big league seasons is over. If the right-hander was dismayed over the slight, he didn't show it. "Every year a lot of guys are left out. Last year I probably didn't deserve to get in," he said. Betances started the week with a run of 18 straight scoreless appearances. Asked about being idle during the All-Star break for the first time, he replied, "It'll be weird. But I'll enjoy those four days."

UP NEXT

Yankees: Masahiro Tanaka (7-2, 4.58 ERA) comes off the DL to start Tuesday night in the third game of the series. Both hamstrings were strained.

Orioles: Andrew Cashner (2-9, 4.39) takes his eighth crack at getting his third win of the year.