St. Louis and San Francisco, three weeks removed from playing to a tie on the West Coast, were less than a minute away from it happening again.

That’s until Greg “The Leg” Zuerlein stepped onto the field.

Zuerlein’s 54-yard field goal with 26 seconds left in overtime gave the Rams (5-6-1) a 16-13 victory over the 49ers (8-3-1) Sunday at the Edward Jones Dome.

“Wow. That’s the case of guys just hanging in there. Guys making plays. Guys in the three different phases just making the plays that we needed to make,” said Rams Head Coach Jeff Fisher. “That’s an outstanding defense they have and they have an exceptional running game. It was just two good teams evenly matched trying to find a way to win it, and we got it.”

Zuerlein also connected for a 53-yard field goal to tie the game 13-13 as time expired in the fourth quarter.

“It’s great to get the win. The biggest thing is we won the game,” Zuerlein said. “Personally, it feels good just to make a game winner. I’ve had some opportunities before and didn’t convert on them, but the biggest thing is just we got the win.”

The story of the game for the Rams was their defense, who shut down Frank Gore, Colin Kaepernick and the 49ers’ offense.

“As a team, that’s maybe the best that we’ve played,” said Rams defensive end Chris Long. “The offense made some plays when they had to. Hat’s off to our guys. They kept fighting. On days like that, we have to pick up the slack and try to make a play or two. We have to take the ball away and we did that.”

The Rams tied the game 10-10 late in the fourth quarter when rookie cornerback Janoris Jenkins recovered a fumble and dove into the end zone for a score.

“I don’t know what they were trying to accomplish there, but we took advantage of one of their mistakes,” Fisher said.

Jenkins has scored three touchdowns in the last two games.

It’s the second time this season the Rams have won a game without scoring an offensive touchdown. The other came in the Seattle game.

Still, Sam Bradford and the Rams offensive had some key drives in the second half and overtime.

“It wasn’t pretty. Obviously there were a lot of things we could have done better,” Bradford said. “Our defense did a great job of keeping us in the game. Fortunately at the end, we were able to make enough plays to win the game.”

The Rams remained undefeated in the NFC West with a 4-0-1 record with one more division game to go at Seattle Dec. 30.

“This was a tough one,” said 49ers Head Coach Jim Harbaugh. “It was a football fight, and we did not win.”

With Danny Amendola out of the lineup due to a foot injury, rookie receiver Chris Givens helped fill the void with a season-high 11 catches for 92 yards.

“Days like this are what we live for,” Givens said. “You really can’t ask for too much more than a football game like this. It was a great game to be a part of.”

Rams running back Steven Jackson has an NFL-best 10,838 yards from scrimmage dating back to 2006.

“We have a lot of room to grow. The one thing about this team that we learned is that guys are going to continue to fight,” Jackson said. “Guys are going to continue to bring their ‘A’ game despite what it looks like, despite what people may think. These group of men believe that we can compete at a high level.”

The Rams, still alive in the NFC playoff hunt, visit Buffalo (5-7) Sunday at noon.