SANTA CLARA, Calif. — After a blowout loss to the Miami Dolphins, the San Francisco 49ers spent this week hammering home the need for a sense of urgency Sunday night against the Los Angeles Rams.

Lest their 2020 season slip away before they reach the halfway point, the Niners and quarterback Jimmy Garoppolo made it clear from the game’s first possession that this week would be different.

With coach Kyle Shanahan pressing the right buttons, Garoppolo shaking off his halftime benching from last week and a stingy defense, the Niners jumped to an early lead and held on for a 24-16 bounce-back win against the Rams on Sunday night.

“When you get embarrassed like that, you can find out a lot about your team,” Shanahan said. “I was very impressed with the character of our team and the way they carried themselves and the way they came out to practice on Wednesday, Thursday and Friday and really the way they responded to all of us getting embarrassed. They tried to get better this week and not worry about anything else, and usually when you do that, you can put together those type of practices, usually the results are better, and I’m glad that they were because I thought they really earned it throughout the week and today.”

The 49ers improved to 3-3 on the season with the win, which was also their first at Levi’s Stadium this season. They also avoided becoming the first losing team from the Super Bowl to have a record below .500 through six games since the 2016 Carolina Panthers.

To make it happen, the Niners got off to a hot start in which Shanahan set Garoppolo up for early success with a number of short throws that got the offense rolling on the game’s opening possession.

Coming off a career-low QBR of 1.4 last week against the Dolphins that ended with him benched in favor of C.J. Beathard at halftime, Garoppolo completed four passes on the first drive, all of which were behind the line of scrimmage.

But the Niners picked up 88 yards after the catch on a drive that covered only 76 yards of actual field, as Garoppolo averaged minus-4.9 air yards per attempt. As it turned out, that drive gave Garoppolo the confidence needed to later push the ball to the intermediate levels, as he posted his best performance of the season on his still-recovering high right ankle sprain.

Garoppolo, who was 18-of-23 on throws of 5 yards or fewer for 155 yards and two touchdowns, credited Shanahan with drawing up a game plan that effectively mixed those short throws with the run game and later afforded opportunities for some bigger plays down the field.

“Kyle is mixing all that stuff up like that, it makes it hard on defenses,” Garoppolo said. “It’s a pick-your-poison type of thing, and Kyle did a great job tonight putting us in good positions. He was on point tonight, so it makes all of our jobs a lot easier.”

Garoppolo finished 23-of-33 for 268 yards with three touchdowns and no interceptions for a passer rating of 124.3. He is the first Niners quarterback since Jeff Garcia in 2003 to throw for 200-plus yards with three touchdowns in the first half of a game.

“Jimmy was hindered last week,” receiver Brandon Aiyuk said. “Jimmy is a baller, so we all knew that he was going to bounce back and play a great game. This week in practice, you can see the urgency, especially in him, and he got back to being Jimmy.”

It helped Garoppolo that he got plenty of contributions from his teammates. Tight end George Kittle served as Garoppolo’s primary target, finishing with seven catches for 109 yards and a touchdown.

And the offensive line, which had yielded 10 sacks and 24 quarterback hits over the past two weeks, was up for the challenge against Aaron Donald & Co. The Rams managed just three hits on Garoppolo and he was not sacked, and the Niners attempted 37 runs despite averaging just 3.3 yards per carry. Donald finished with two tackles and one quarterback hit.

“I thought the O-line as a whole just did a phenomenal job,” Garoppolo said. “It started with the run game and then the pass game, the pockets were clean all night … I didn’t get hit very much, felt great coming out of this game. When the O-line plays like that, it sets a tone for our whole offense, and they did it tonight.”

The defense, meanwhile, held the Rams to 4-of-12 on third down, limited quarterback Jared Goff to a 35.5 QBR and cornerback Jason Verrett came up with his first interception since Sept. 11, 2016, to kill a Rams drive in the end zone.

The 49ers head to New England next week to play the Patriots to kick off a stretch in which they will also visit the Seattle Seahawks, host the Green Bay Packers, travel to play the New Orleans Saints and then meet the Rams again, this time in Los Angeles.

It’s the toughest stretch of a schedule that ESPN’s Football Power Index calls the hardest remaining in the league. But now they enter it with a win against a division foe under their belt and confidence that they’re closer to being the team they believe they can be.

“[We’re] just getting back to the brand of football we know we’re capable of playing,” defensive lineman Arik Armstead said. “Running the ball, moving the chains, taking the life out of a defense, and then on defense, big stops, three-and-outs, eliminating explosives, making them drive all the way down the field to beat us. I think we just got back to playing like we know how to play.”