49ers wide receiver Deebo Samuel (19) celebrates after a touchdown during a 27-24 overtime win over Rams on Sunday, Jan. 9, 2021 (Courtesy Photo)

The San Francisco 49ers overcame an early 17-0 deficit to clinch the final playoff berth position in a win or go home scenario.

49ers kicker Robbie Gould converted a 24-yard field goal with 2:45 left in overtime and rookie defensive back Ambry Thomas intercepted Matthew Stafford on the next possession, enabling San Francisco to earn a 27-24 triumph victory over the Los Angeles Rams on Sunday at SoFi Stadium.

The sixth-seeded 49ers will next travel to face the third-seeded Dallas Cowboys on Sunday at AT&T Stadium.

“Our guys are so resilient,” 49ers coach Kyle Shanahan said. “I’m very proud of them, and I’m just glad that we get to go into the tournament and be a part of it.”

With the loss, Los Angeles fell out of the No. 2 NFC seed and potentially cost themselves a chance at hosting multiple playoff games. The Rams did still manage to win the NFC West after the Arizona Cardinals lost to the Seattle Seahawks.

The No. 4 seed Rams are set up to host the No.5 Cardinals in the first ever playoff game at SoFi Stadium next Monday night.

“Our guys did a good job being able to navigate through the season. To be able to still win the division is a good accomplishment, but I don’t know that right now is a time to celebrate that,” Rams coach Sean McVay said. “We’ll look at this film, we’ll clean it up, and we’ll move forward the right way. This is a resilient group.”

San Francisco quarterback Jimmy Garoppolo passed for 316 yards and threw two costly interceptions, but responded when the team needed him most, as he connected with Jauan Jennings on a 14-yard touchdown pass with 26 seconds left in regulation to force overtime.

Deebo Samuel had four receptions for 95 yards, rushed for a touchdown and threw a scoring pass to Jennings in regulation for the 49ers. Brandon Aiyuk had six catches for 107 yards.

“Getting off to a slow start and then coming back like we did, it took everything,” said Garoppolo. “We say that a lot of weeks, but this one really did. I felt it after the game. I know a lot of guys in that locker room did. It was worth it, though. It was one of those games you won’t forget any time soon.”

Stafford threw for 238 yards and three touchdowns, but was unable to lead Los Angeles on a game-winning drive, resulting in the overtime interception by Thomas.

“There are some plays out there I want back,” Stafford said. “I guess (a division title) is nice. It means you get a home playoff game. But we would have rather won the game, for sure.”

Cooper Kupp finished with seven catches for 118 yards and scored late in regulation, becoming the fourth player in NFL history to lead the league in receptions, yards receiving and TD catches this season.

Cam Akers returned just five months after tearing his achilles and ran the ball five times and caught three passes after his remarkable recovery for the Rams.

Stafford connected with Tyler Higbee for two touchdowns in the second period. San Francisco quickly responded when Samuel had two scores of his own in the third to tie the game at 17-17.

A big interception by Jalen Ramsey late in the fourth allowed the Rams to go on a nine play, 92-yard drive that ended with Stafford finding Kupp for a four-yard touchdown to take a 24-17 lead.

Los Angeles was unable to hold the lead in the final 2:29, allowing Garoppolo to find Jennings on the next possession for a 14-yard score just before the end of regulation, allowing the 49ers to convert a game-winning field goal in overtime.

“You’ve got to play good football, but you’ve got to be resilient too. Right now, it’s testing us,” Stafford said. “We lost the football game that we had chances to win and would have felt great winning that game and winning the division the way we wanted to win the division, but we’re a resilient group and we’ll be ready to go.”

“You’ve got to finish. Our guys came out ready to go but you’ve got to play four quarters, or five quarters in this instance,” McVay said. Credit them, they did a good job. I have to do a better job, we can all do a better job, and fortunately this isn’t the end for us.”