The Boston Red Sox will host the New York Yankees in the American League Wild Card Game on Tuesday night after the rivals’ biggest stars came up big when their teams needed it most Sunday.

Aaron Judge drove home the winning run with a one-out single in the ninth inning of the Yankees’ 1-0 win over the visiting Tampa Bay Rays, while Red Sox slugger Rafael Devers‘ two-run homer in the ninth inning broke a 5-5 tie against the Nationals in Washington.

The victories helped Boston and New York avoid several tiebreaker possibilities that involved the looming Seattle Mariners and Toronto Blue Jays.

Devers’ second homer of the game — and 38th of the season — came on a drive to straightaway center field off Kyle Finnegan on a 2-1 pitch with one out after Kyle Schwarber reached on an error. Boston went on to win 7-5.

“I know that nobody believed in us at the beginning of the season,” Devers, goggles perched atop his head for the playoff-clinching festivities, said through an interpreter. “This is just our first celebration.”

The homer capped a four-hit, four-RBI afternoon for Devers, brought teammates bounding out of the dugout and prompted chants of “Yankees suck!” from some of Boston’s fans who could be heard throughout much of the afternoon in a crowd of 33,986 at Nationals Park.

Meanwhile, at Yankee Stadium, shortstop Gio Urshela made a Derek Jeter-esque catch, charging recklessly into the visiting dugout, to help New York finish the year 92-70 and punch a fifth consecutive postseason ticket after nearly falling into a labyrinth of tiebreaker scenarios.

“It’s been a crazy, wild, tough year,” Yankees manager Aaron Boone said. “Fitting that it would come down to the last day to get in, but I love our group.”

Sunday’s results had both the Mariners and Blue Jays on the outside looking in. Seattle lost its regular-season finale to the Los Angeles Angels 7-3, ending a magical late-season run that saw the Mariners win 11 of their last 14 games. The Blue Jays crushed the Baltimore Orioles 12-4 but needed a loss by the Yankees or Red Sox to set up a tiebreaker to decide the final wild-card berth.

“It hurts,” AL MVP candidate Vladimir Guerrero Jr. said through an interpreter. “Knowing that you won 91 games and you didn’t make the playoffs, it really hurts me, it hurts all my teammates. That’s just going to make me stronger to come back next year even better than this year.”

Rougned Odor led off the ninth with a single against Josh Fleming (10-8), just New York’s second hit. Pinch runner Tyler Wade advanced to second on Gleyber Torres‘ fly out to the warning track in center, and Anthony Rizzo moved Wade to third with a one-out single.

Andrew Kittredge came on to face Judge, who ripped a 104.4 mph line drive off the right-hander’s glove. The ball skipped toward drawn-in second baseman Brandon Lowe, whose off-balance throw home wasn’t nearly in time to catch a sliding Wade.

Teammates swarmed a smiling Judge midway between first and second, and fans chanted “MVP! MVP!” at the face of the franchise during an on-field interview. The clutch single was Judge’s eighth go-ahead hit in the eighth inning or later this season, which is the most by a Yankees player in a season since 1961, according to ESPN Stats & Information research.

“I wouldn’t say we exhaled,” Judge said. “We still have a lot of work to do.”

It was a sentiment shared by Red Sox manager Alex Cora.

The Red Sox, faced with several Game 163 possibilities should they have lost on Sunday, fell behind 5-1 to the Nationals thanks in part to a shaky start by ace Chris Sale, who went just 2⅓ innings.

Devers led off the fourth with a drive off a 1-2 fastball from Joan Adon, a 23-year-old right-hander who struck out nine batters in 5⅓ innings in his major league debut. Devers added an RBI single off Erick Fedde in the seventh that brought the visitors within 5-3, and Alex Verdugo‘s two-run double that inning tied it at 5.

One bit of negative news for Boston: Slugger J.D. Martinez left in the sixth inning with a sprained left ankle.

The Yankees suffered an injury scare of their own after Urshela’s brazen bolt into Tampa Bay’s dugout. With two outs in the sixth, Urshela sprinted 126 feet after Austin Meadows‘ popup from a shifted infield formation. He caught it a stride before reaching the top step of the Rays’ dugout, then appeared to leap from the warning track full speed into an empty spot on the bench.

Plate umpire Angel Hernandez flipped over the railing chasing after him to confirm the out call, while Tampa Bay players quickly waved toward the home dugout for a trainer. Boone ran across the field and was followed by members of the medical staff. Pinstriped teammates gathered near the dugout entrance while Urshela was tended to.

“He looked like a missile flying in there,” Boone said. “It scared me to death.”

Urshela emerged about a minute later and limped back to the Yankees bench to chants of “Gio! Gio!” Astoundingly, he returned to shortstop for the seventh inning despite a stiffening bruise on his left thigh. He grounded out in his next at-bat in the eighth inning, then was replaced by Andrew Velazquez in the ninth.

Jeter, inducted into the Hall of Fame last month, famously bloodied his face diving into the third-base seats after catching a popup in a game against rival Boston on July 1, 2004.

Urshela isn’t sure how he landed, but he’s glad it wasn’t on his head. He opened his eyes after crashing and saw the ball in his glove, then worried momentarily that he was seriously injured.

“It felt like a lot of pain in that moment,” he said.

Boone said there wasn’t any structural damage, but Urshela will be reevaluated Monday before determining his future availability. The slick-fielding infielder had a more prominent limp after the game.

Information from The Associated Press was used in this story.