BALTIMORE — Nick Martinez retired 18 of the 19 batters he faced and allowed just one hit across six innings as the Tampa Bay Rays beat the Baltimore Orioles 3-1 at Camden Yards, avoiding a three-game sweep and maintaining a three-game lead in the American League East.

The victory snapped a brutal stretch in which Tampa Bay had lost seven of its past nine games and three straight series. Martinez, 36, struck out four and threw 86 pitches — 60 for strikes — while permitting only a one-out double by Colton Cowser in the third inning and allowing just five hard-hit balls.

“Overall, he was just excellent for us,” manager Kevin Cash said. “We needed a big start, obviously, for the obvious reasons, and Nick provided that.”

Martinez improved to 13-4 with a 2.93 ERA, fifth among qualified American League starters. The outing was the Rays’ first quality start since Ian Seymour allowed three runs in six innings on Aug. 15.

“Every game counts. Every game matters,” third baseman Junior Caminero said through interpreter Kevin Vera. “Winning today to kind of give us strong momentum toward the end of this road [trip] against Detroit and, again, just get us on the right track, it was super important.”

The Orioles, who had won eight of their past nine matchups against the Rays, got a strong start from former Ray Shane Baz, who carried a two-hitter into the sixth. But Tampa Bay broke through with two outs in the frame when Yandy Díaz slapped a two-strike single to right field and hustled to third on a hit by Jonathan Aranda. Baz then bounced a two-strike curveball that caromed off catcher Samuel Basallo’s mask, allowing Díaz to dash home for the game’s first run. Caminero pushed a single into center to score Aranda, Liam Hicks walked, and Chandler Simpson smacked another two-strike single to center off lefty reliever Grant Wolfram to make it 3-0.

“Every time Martinez pitches for us, he brings a ton of energy, and we all rally behind him,” DH Díaz added through Vera. “He’s done a great job all year, so it’s not surprising what he was able to do today. Again, he just pushed us forward to the win.”

Martinez, who has served as the Rays’ steady veteran presence all season, said he entered the start with conviction behind all his pitches. Orioles manager Craig Albernaz credited Martinez’s ability to pair his three fastballs and changeups effectively.

“At this time of year, and looking at our schedule, we’re facing a lot of guys whose backs are up against the wall, right?” Martinez said. “They have to win every game for them to make it to the playoffs, so we’ve just got to match the energy, bring the energy and keep playing to win ballgames. Keep doing what the game’s asking us to do and playing our style, and things will turn around. Obviously you want to be winning every game you can, but the most important games are still in front of us.”

“A bunch of guys played a role in that inning,” Cash said of the sixth. “I don’t think we’re firing on all cylinders right now, but you’ll take it however you can get it.”

The Rays head to Detroit for their next series as they look to build on the momentum heading into the final weeks of the regular season.