It was no simple task, but the Red Sox secured a spot in the American League Wild Card Game by finishing off a three-game weekend sweep of the Nationals on Sunday.

Boston held on to top Washington by a final score of 7-5 at Nationals Park, which ensures that they will not have to play in a tiebreaker on Monday.

Chris Sale, making his ninth and final start of the regular season for the Sox, was unable provide length in his first-ever appearance against the Nationals.

After getting off to a solid start in which he struck out the side in the bottom of the first, the veteran left-hander ran into some trouble in the second when he gave up a leadoff double to Josh Bell. Jordy Mercer followed by ripping another double off Sale that brought in Bell and gave Washington their first lead of the day at 1-0.

The Nationals doubled their advantage an inning later, as Sale loaded the bases with one out on a walk and a pair of singles before issuing another free pass to Ryan Zimmerman that plated Lane Thomas from third to make it a 2-0 contest.

Despite throwing just 62 pitches (37 strikes), Sale’s afternoon came to a close right then and there, with Red Sox manager Alex Cora forced to turn to his bullpen far earlier than expected.

Hirokazu Sawamura was the one who got the first call from Cora out of the Boston bullpen, and despite inheriting a mess, he officially closed the book on Sale’s outing by getting Mercer to ground into a huge inning-ending, 6-4-3 double play.

To that point, the Red Sox lineup had been stymied by Nationals starter Joan Adon, managing all of one hit off the right-hander making his first career big-league start on Sunday.

Rafael Devers changed that quickly, though, as he led off the fourth inning by clubbing a 432-foot solo blast to deep center field off a 1-2, 95 mph sinker on the outer half of the plate from Adon.

Devers’ 37th home run of the season cut Boston’s deficit in half at 2-1, but that was all they got in the fourth after J.D. Martinez struck out, Alex Verdugo unsuccessfully tried to turn a one-out single into a one-out double, and Hunter Renfroe fanned on three straight pitches.

Sawamura continued to keep the Nationals off the board in the bottom of the fourth, presenting the Sox with the opportunity to get something going in the top of the fifth after the pinch-hitting Christian Arroyo and Enrique Hernandez reached base with one out on a walk and base hit.

A wild pitch from Adon allowed both runners to advance into scoring position, but Boston could not capitalize — as Kyle Schwarber and a struggling Bogaerts rolled over back-to-back groundouts to extinguish the threat.

Perhaps taking advantage of the Sox’ inability to score, the Nats jumped on the newly-inserted Garrett Richards in their half of the fifth. Richards yielded a leadoff double to Alcides Escobar and intentionally put the dangerous Juan Soto on base.

A passed ball from Richards moved Escobar and Soto up to second base for Bell, who drew a five-pitch walk himself to fill the bases once again. Richards recorded the first out of the inning, but allowed Escobar to score from third on an RBI groundout off the bat of Mercer before serving up a two-run double down the right field line to Alex Avila.

Avila, playing in his final major-league game on Sunday, put Washington up 5-1, though is counterpart in Christian Vazquez got one of those runs back in the sixth when he drove in Jose Iglesias on an RBI single off Nationals reliever Patrick Murphy — thus making it a 5-2 ballgame.

Iglesias came into the game as a pinch-hitter for Martinez, who suffered a left ankle sprain after tripping on the second-base bag while running out to right field in the middle of the fifth inning. He was replaced in right field by Renfroe, while Iglesias took over at second base and Hernandez shifted to center field.

Following all that defensive shifting, Martin Perez took over for Richards in the bottom of the sixth inning. The left-hander maneuvered his way around a two-out walk in an otherwise clean frame of work.

A half-inning later, the Boston bats continued to chip away at the deficit in front of them while matched up against Erick Fedde.

Schwarber ignited the rally with a one-out single that was followed by another base hit courtesy of Bogaerts. Devers then plated Schwarber from second on an RBI single to trim Washington’s lead down to two runs. He also moved Bogaerts up to third base.

Iglesias may have popped out to foul territory for the second out of the seventh, but Verdugo did not let a prime scoring opportunity go to waste.

Making up for his earlier base-running gaffe, Verdugo laced a game-tying, two-run double to the gap in right-center field, driving in Bogaerts from third and Devers all the way from first.

Verdugo’s clutch double knotted things up at five runs apiece, and Garrett Whitlock — who was activated from the injured list on Sunday after a two-week absence — kept it that way going into the eighth by fanning two in a scoreless bottom half of the seventh.

Bobby Dalbec pinch-hit for Whitlock in the top half of the eighth, which paved the way for Eduardo Rodriguez to take over for the right-hander. Rodriguez, who threw 93 pitches in his start on Friday, needed all of eight pitches — six of which were strikes — to retire the Nats in order in the latter half of the eighth.

Potentially down to their final three outs in the ninth, Schwarber led off against Kyle Finnegan by reaching base on a fielding error committed by Mercer, which would prove to be costly for Washington.

That being the case because after Bogaerts struck out, Devers came through with the hit of the night — if not the season.

On a 2-1, 87 mph splitter on the outer half of the plate from Finnegan, Devers obliterated his second home run of the day, with this one leaving his bat at a scorching 113.4 mph and traveling a whopping 447 feet over the center-field wall.

By going yard for the 38th time this season, the 24-year-old slugger not only came through for the Sox yet again, but he also gave them their first lead of the day at 7-5.

Nick Pivetta, who made his most-recent start on Thursday, was called upon to end things in the bottom of the ninth. The right-hander did just that by slamming the door on the Nationals to preserve the 7-5 victory for the Sox and notch his second career big-league save.

With the win, the Red Sox finish the regular season with a record of 92-70. They also punched their ticket to the postseason, as they will be hosting the Yankees, who defeated the Rays on Sunday, in the American League Wild Card Game at Fenway Park on Tuesday.

Boston will turn to right-hander Nathan Eovaldi for that all-important contest, while New York will roll with fellow righty Gerrit Cole.

First pitch from Fenway Park on Tuesday night is scheduled for 8:08 p.m. eastern time on ESPN.

More must-reads:

TODAY'S BEST
Damian Lillard has sobering response to rumor he's unhappy with Bucks
White Sox accomplish unenviable feat not seen since 1901
Bill Belichick says he’s only coached one rookie who was NFL-ready from Day 1
Mike Trout makes his thoughts on a trade from Angels abundantly clear
Jayden Daniels' camp reportedly frustrated with team favored to draft him
Detroit Lions safety Kerby Joseph recovering from hip surgery after controversial hits
Duke basketball's mass exodus continues
Scottie Pippen's youngest son commits to top Big Ten school
Clippers get devastating Kawhi Leonard update ahead of Game 1
Braves' Spencer Strider offers clarity on his unique elbow injury
Terry Pegula puts big share of Bills up for sale
NFL coaches make bold Michael Penix Jr. draft claims
Deleted Instagram video sparks FAA investigation of Rockies amid turbulent season
Longtime NFL executive Bill Tobin dies
Avalanche goaltender confirms retirement after short, injury-marred career
Analyst insists that the Raiders like this divisive quarterback prospect
NHL approves sale, relocation of Arizona Coyotes
Eastern and Western Conference play-in teams' odds to advance take hit with brutal injuries
NFL decides fate of five players suspended for gambling
Injured Rangers ace ahead of schedule in rehab efforts