ST. PETERSBURG, Fla. (AP) — The Tampa Bay Rays struggled during a six-game homestand against a pair of last-place teams but were able to break even due to three walk-off wins.

Kevin Kiermaier drove in four runs, including a solo homer during a two-run ninth inning, and the Rays avoided a three-game sweep by beating the Seattle Mariners 7-6 on Wednesday.

"We did enough to win today," Kiermaier said. "You can call it an ugly win or whatever, we'll take as many as we can."

Kiermaier tied it at 6-6 on a leadoff homer against Matt Magill (3-1). The Rays then loaded the bases on Willy Adames' single, a double by Mike Brosseau, and an intentional walk to pinch-hitter Ji-Man Choi with no outs before Magill's wild pitch with Tommy Pham batting allowed Adames to score the winning run.

"Kind of a bummer," Magill said. "I cost my teammates a win."

Daniel Vogelbach had a solo homer and Mallex Smith added a two-run triple off Emilio Pagan (3-2) as the Mariners went up 6-5 in the top of the ninth.

Tampa Bay entered the game a percentage point behind Oakland for the second AL wild card. The Athletics were at home later Wednesday against the New York Yankees.

Brosseau had a run-scoring single in the 13th inning of a 1-0 win over Detroit Saturday, while Choi knocked in a pair with a ninth-inning single during a 5-4 victory Sunday over the Tigers.

Tim Lopes had two RBIs for the Mariners, who head home after a 6-3 road trip.

"We almost pulled off a sweep here, really close," Seattle manager Scott Servais said.

Kiermaier put the Rays ahead 4-3 on a two-run single in the fourth and added a sixth-inning, run-scoring groundout.

Seattle took a 3-2 advantage in the fourth on Kyle Seager's RBI grounder and Lopes' two-run single. Rays right fielder Guillermo Heredia prevented two more runs from scoring with a nifty running catch in the right-field corner on Jake Fraley's drive.

Heredia, mired in a 1-for-23 slide, made it 2-0 on his third-inning homer off Wade LeBlanc.

"I've got to give Guillermo Heredia some love because he had a huge homer, but he made a play down the right-field line," Kiermaier said. "Who knows what would have happened at that point in the game? That changes everything. That was huge."

Fraley made his major league debut starting in center and became the 63rd player used by the Mariners this season, one away from the MLB record set by Texas in 2014.

Seager went 0 for 4 and had a 14-game hitting streak end.

Pham walked in the first, stole second and third, and scored on Travis d'Arnaud's sacrifice fly.

Tampa Bay ace Charlie Morton was bidding for his 14th win but struggled in a five-inning, 99-pitch start, giving up three runs, four hits, two walks and striking out three. The righty had struck out 29 and walked none in his three previous outings.

TRAINER'S ROOM

Mariners: OF Mitch Haniger (ruptured testicle) was the DH at Triple-A Tacoma Tuesday but will need to play a whole game defensively before returning.

Rays: RHP Yonny Chirinos (right middle finger inflammation) will play catch this weekend. ... RHP Tyler Glasnow (right forearm) had his second bullpen session. ... OF Avisail Garcia (right oblique) should be back Saturday.

BIG MEN

The Rays purchased the contract of RHP Aaron Slegers from Triple-A Durham. At 6-foot-10, he is the tallest player in team history and, according to Baseball Reference, tied for the second-tallest in the majors behind 6-foot-11 Jon Rauch. "I saw (college basketball analyst) Jay Bilas at the barber shop," Slegers said. "I think he double-taked. He couldn't believe he didn't know every seven-footer in the city."

TOSSED

Rays 1B Jesus Aguilar was ejected for the first time in his career for arguing with home plate umpire John Libka after a called third strike in the sixth.

UP NEXT

Mariners: LHP Justus Sheffield (0-0) will be recalled from Double-A Arkansas to make his first major league start Friday night against Toronto.

Rays: LHP Ryan Yarbrough (11-3) starts Thursday night at Baltimore against RHP Asher Wojciechowski (2-6)

More From 1460 ESPN