SEATTLE — The stars were aligning for the Baltimore Orioles.

After falling behind the Seattle Mariners by four runs, the Orioles pulled within three and had the heart of their order coming up with two on and two outs in the eighth inning.

When Manny Machado welcomed Seattle closer Steve Cishek with an RBI single to pull Baltimore within two, the Orioles looked as if they might rally for an eighth consecutive win.

However, Cishek struck out slugger Chris Davis to strand two runners in the eighth, and then he retired three of the four batters he faced in the ninth, including a game-ending strikeout as the Mariners held on for a 5-3 win.

“A sigh of relief,” Cishek said when asked how it felt to catch Pedro Alvarez swinging for the final out of the game. “We needed a win.”

Taijuan Walker made a triumphant return to the mound, and Seattle teammate Seth Smith hit a two-run homer as the Mariners ended Baltimore’s winning streak.

Walker, who missed his previous turn in the rotation due to foot soreness, allowed just one run on four hits over 6 1/3 innings.

“My arm felt really good, and the ball was coming out really good,” Walker said.

Walker (4-6) retired the first 11 batters of the game and had a shutout going through six innings. A leadoff home run by Orioles left fielder Hyun Soo Kim in the seventh ended the shutout bid and cut Seattle’s lead to 4-1.

Kim’s home run was the Orioles’ 56th of the month, setting a June record for homers by any team.

Kim added an RBI single off Seattle reliever Joaquin Benoit in the eighth, pulling the Orioles to within 5-2 before Cishek came on to try and hold the lead.

The Orioles (47-31) had a leadoff hit in the ninth before Cishek got the final three outs to earn his 19th save. Alvarez struck out on a 3-2 pitch with a runner on first base to end the game.

“It’s my job; it’s what I get paid to do,” Cishek said of earning the four-out save. “I just go out and do what my teammates ask me to do.”

Smith hit his seventh home run of the season, while Nelson Cruz went 2-for-2 with a pair of doubles for Seattle (40-39). Mariners first baseman Dae-Ho Lee drove in two runs, both of them coming after Kyle Seager was intentionally walked in front of him, in the fifth and seventh innings.

Smith’s two-run homer helped the Mariners jump out to a 4-0 lead in the fifth inning.

Smith’s seventh home run of the season came on a 2-1 pitch, which he lined into the seats in right field to put Seattle ahead 3-0. The Mariners then loaded the bases for Lee, whose RBI single to right field increased the lead to 4-0.

Baltimore right fielder Mark Trumbo threw out Cruz on a force play at third base on the play as Cruz held up on the bloop fly ball to right.

That marked the final batter for Baltimore starter Chris Tillman, who was charged with four runs and six hits over 4 2/3 innings.

“Chris wasn’t quite as crisp as he’s capable of being,” Orioles manager Buck Showalter said.

Tillman (10-2) issued back-to-back walks with two outs in the first inning, leading to a 1-0 deficit when Seager singled to left. Seager’s two-out hit brought Robinson Cano around from second base.

Walker retired the first 11 batters, and it might be said that he actually got 12 in a row. After taking a no-hitter two outs into the fourth, Walker gave up a long single to Machado, who was thrown out after taking too wide a turn around first base to end the inning.

Machado extended his hitting streak to nine games with the single.

The 1996 Oakland A’s had 55 homers in June, the record snapped by Baltimore on Thursday.

The record and a 19-9 mark in the month of June left the Orioles feeling satisfied despite the end of their winning streak.

“That’s three winning months, and that’s the consistency we’ll have to have,” Showalter said. “We’re going to have to continue to do that to stay where we are (atop the American League East).”