SANTA CLARA, Calif. (AP) — After a nearly two-month stretch that featured one win and far too many disappointments, the San Francisco 49ers were running out of time to establish an identity this season.

An opening 18-play touchdown drive against the rival Los Angeles Rams was a pretty good start.

Jimmy Garoppolo capped that long drive with the first of his two touchdown passes, Jimmie Ward returned one of his two first-quarter interceptions for another score and the 49ers beat the Rams 31-10 on Monday night for their first home win in more than a year.

“It got us into a rhythm for sure,” Garoppolo said. “That’s the way we want to do it. Just running the ball, converting on third down and then score at the end. I don’t want to say it took their soul away but it definitely did something.”

The Niners (4-5) had lost four of five games and were in danger of falling out of the playoff race before putting together a complete performance in their fifth straight win against the Rams (7-3).

Garoppolo threw TD passes to George Kittle and Deebo Samuel, Samuel also ran for a score and Ward delivered the big plays defensively to give San Francisco its second home win in the past two seasons. The other also came against the Rams on Oct. 18, 2020.

It all started on the ground, where coach Kyle Shanahan had set an audacious goal of 40 carries that the Niners exceeded with 44 runs for 156 yards.

“I almost regretted it because it's tough to do,” Shanahan said. “I’m glad I set it. We came through with it. It’s a huge team goal.”

San Francisco had its most rushes in a regular-season game in nine years. The Niners used a similar formula two years ago when they made it to the Super Bowl.

Last week, San Francisco had 11 carries for 39 yards in a 31-17 loss to Arizona.

“If you want to establish any type of dominance, especially in the trenches, I think that is necessary,” left tackle Trent Williams said. “You got to run the ball and got to make your opponents respect it.”

The Niners sealed the game when Garoppolo connected on a 40-yard TD to Samuel on fourth-and-6 early in the fourth quarter that made it 31-7.

Garoppolo finished 15 for 19 for 182 yards and the two TDs.

The Rams lost for the second straight week with Matthew Stafford once again throwing two interceptions, including one returned for a touchdown.

Los Angeles struggled to get into any rhythm offensively in the first game after receiver Robert Woods went down with a season-ending knee injury last week in practice.

“This was a humbling night for us as a team, and a great opportunity for us to be able to take a deep breath, step away, look at the things that we need to correct, particularly offensively over the last couple of weeks,” coach Sean McVay said.

Odell Beckham Jr. made his Los Angeles debut after signing last week but had only two catches for 18 yards.

Recently acquired edge rusher Von Miller also played for the first time with the Rams and had three tackles but didn't put pressure on Garoppolo.

Stafford went 26 for 41 for 243 yards with one TD, two interceptions and nearly a third that K'Waun Williams trapped on his backside only to have it wiped off by a penalty.

TAKE IT AWAY

Ward intercepted Stafford on Los Angeles' first two drives of the game after coming into the night with two INTs in 85 games and none since 2016.

The first came on a deep heave by Stafford to Beckham that went right to Ward. The next came on a quick throw that tight end Tyler Higbee bobbled right into Ward's hands, leading to a 27-yard TD return.

Ward became the seventh player since 2000 with two interceptions, including a pick-6, in the first quarter.

KEEP IT AWAY

The Niners did a good job keeping the ball away from Stafford in the first half. They had an 18-play, 93-yard drive that took 11:03 off the clock after Ward's first interception. It was capped by an 8-yard TD pass from Garoppolo to Kittle.

That was the second opening drive of at least 18 plays in the past eight seasons, with Houston doing it earlier this year against New England.

San Francisco then had an 11-play, 91-yard drive on it second possession capped by Samuel's 8-yard run to take a 21-7 lead.

FAKE IT

McVay made a curious decision when he called for a fake field goal on fourth-and-8 from the 17 with 18 seconds left in the first half.

Holder Johnny Hekker completed a 2-yard pass to Kendall Blanton that was well short of the first down.

INJURED

Rams: RB Darrell Henderson left in first quarter to be evaluated for a concussion but returned late in the first half.

49ers: RT Jaylon Moore (knee) left the game in the first half.

UP NEXT

Rams: Los Angeles has a bye next week before visiting Green Bay on Nov. 28

49ers: Visit Jacksonville on Sunday.

___

More AP NFL: https://apnews.com/hub/nfl and https://apnews.com/hub/pro-32 and https://twitter.com/AP_NFL