SANTA CLARA -- The 49ers needed two wins in their final two regular-season games to reach their goal of earning homefield advantage throughout the NFC playoffs.

Before the winner-take-all showdown against the Seattle Seahawks, the 49ers had to take care of business Saturday night against the Los Angeles Rams.

It was not easy -- far from it, in fact.

“You try not to look ahead,” 49ers coach Kyle Shanahan said after the 49ers’ 34-31 victory over the Rams at Levi’s Stadium. “I thought we had to win this game no matter what.

“Now, winning this, you don’t have to worry about anything. Now we’ve got one game here left in our season before the playoffs. (We) got eight days to get ready for it and we’re pumped about that.”

Here are the 49ers’ grades from their Week 16 victory over the Rams:

Rushing Offense

The 49ers’ raw rushing numbers were not bad at all. In fact, the 49ers averaged 5.2 yards per rushing attempt.

But the 49ers did not have a consistent running attack that enabled them to pick up first downs and control the clock.

Raheem Mostert continues to be the 49ers’ top back. He gained 53 yards on 11 rushing attempts. He had a 19-yard touchdown run to keep his streak alive with five consecutive games with a rushing touchdown.

Tevin Coleman added 33 yards on five rushing attempts. And wide receiver Deebo Samuel check in with 28 yards on three carries. Matt Breida has fallen out of favor and did not have a rushing attempt.

Grade: B

Passing Offense

The passing game was a mixed bag for the 49ers. For most of the game, the pass protection had difficulties against the Rams’ pass rush. Quarterback Jimmy Garoppolo threw two interceptions and was under pressure most of the game. He was sacked six times.

But when the 49ers needed it, Garoppolo and the passing game came through in a big way. Garoppolo completed 16 of 27 pass attempts for 248 yards and one touchdown.

Garoppolo led the 49ers on two late go-ahead drives. He capped one drive with a 7-yard touchdown pass to tight end George Kittle.

Then, with the score tied in the closing minutes, he twice converted third-and-16 passes to Kendrick Bourne and Emmanuel Sanders. The second of those was a 46-yarder to Sanders to set up the winning points.

Grade: C-plus

Rushing Defense

The 49ers did not allow Todd Gurley and the Rams running game to be any kind of factor. Gurley had just 48 yards on 15 rushing attempts, though he did score two touchdowns.

Linebackers Dre Greenlaw led the 49ers with 13 tackles, while Fred Warner added 11 tackles. Richard Sherman, Kentavius Street, Solomon Thomas and DeForest Buckner each had a tackles for loss,

Grade: B-plus

Passing Defense

Unlike the first 49ers-Rams meeting in October, L.A. quarterback Jared Goff was not affected too much by the pass rush. This time, he did a very good job of moving the pocket and of throwing the ball away any time the rush got close to him.

Nick Bosa got some consistent pressure and forced two incomplete passes with his pressure, but the 49ers did not register a sack. In fact, the 49ers have just three sacks in the team’s past four games.

Fred Warner supplied one of the plays of the game when he intercepted Goff at the sideline and returned it 46 yards for a touchdown in the closing minute of the first half.

That play helped balance out what was an otherwise strong game for Goff, who completed 27 of 46 pass attempts for 323 yards. His touchdown passes to Cooper Kupp and Brandin Cooks both came with cornerback Ahkello Witherspoon in coverage.

Grade: B-minus

Special Teams

This might have been the best game of the season for special teams, which began on a high note with Richie James’ 81-yard kickoff return to set up the 49ers’ first points of the game.

Of course, the evening concluded with Robbie Gould’s game-winning 33-yard field goal as time expired.

Punter Mitch Wishnowsky had a very good game, as he averaged 43.6 net yards on five punts.

Grade: A

[RELATED: 49ers beat Rams for Beathard]

Overall

The 49ers had plenty of problems on offense and defense throughout the game. The Rams had solid plans on both sides of the ball, and they made it difficult for the 49ers, to be sure.

But the 49ers made enough plays on defense, offense and special teams to pick up this crucial victory and set up the biggest regular-season game the 49ers have played in many, many years.

With all the emotion of the day, this was huge. Quarterback C.J. Beathard’s brother, Clayton, was the victim of a fatal stabbing in Nashville early Tuesday morning. Kittle called it the “toughest game” he has ever had to play in his career.

The 49ers did what they had to do to win. And that’s all that matters.

Grade: B-plus