BALTIMORE -- The Ravens had no use for Raheem Mostert four years ago.

On Sunday, he delivered his best performance as an NFL running back, and was a big reason the 49ers had a chance to beat Mostert's former team.

In a game featuring two of the league's top teams, Justin Tucker kicked a 49-yard field goal on the final play of regulation to provide the Ravens with a 20-17 victory over the 49ers.

The Ravens own the NFL's top-ranked offense, but Mostert was the most dynamic player on this day. He accounted for a big chunk of the 49ers’ offensive production with 146 yards and one touchdown on 19 carries.

Mostert had the most rushing yards for a 49ers player since Carlos Hyde ran for 193 on Dec. 11, 2016, against the New York Jets.

“I didn’t really have a good experience when I was here, but I made the most out of my opportunities,” Mostert said after his career-best performance. “I wasn’t holding onto a grudge, but I really did want to show the organization what they missed out on.”

Mostert joined the Ravens in mid-October of the 2015 season after being claimed off waivers. He was an undrafted rookie from Purdue who spent time with the Philadelphia Eagles and Miami Dolphins before landing with the Ravens. Mostert was a special-teams ace for Baltimore over the next two months while seeing action on just two offensive snaps.

 

“Originally, I was playing my ass off on special teams,” Mostert said. “And I thought I was going to be here for a while.”

“I can attest that Raheem was balling, too,” said 49ers fullback Kyle Juszczyk, who played for the Ravens at the time.

But, then, things turned weird, according to Mostert.

“I was there for eight weeks already, and they decided they wanted to cut me after one game,” Mostert said. “I don’t know what the situation was. They decided they were going to cut me. I go into the office, and they tell me I’m being released and for me to go back home to my apartment. And they called me back in and said, ‘Ah, just kidding, we’re not going to release [you].’ ”

Mostert said he was cussed out by coaches for going home. One week later, the Ravens officially released him, he said.

Mostert had a brief stay with the Chicago Bears in 2016 before ending up with the 49ers.

Over the course of his time with the 49ers, he has emerged as a valued backup running back, as well as the team’s top special-teams player.

Coach Kyle Shanahan and running backs coach Bobby Turner decided to stick with the hot hand against the Ravens after the 49ers’ ground game started having success with Mostert playing ahead of starter Tevin Coleman.

“I thought he was running great once he got in there,” Shanahan said. “I saw a few of the runs he made. He was pressing it real well.”

Said 49ers left guard Laken Tomlinson: “Raheem did a really good job of moving the rock. That definitely gave us momentum as an offense, and guys feed off that. He did a really good job with the decisions he made.”

With the 49ers down 14-7, Mostert tied the score with a 40-yard touchdown run in the second quarter. He picked up big blocks from tackle Mike McGlinchey, guard Mike Person, tight end George Kittle and receiver Richie James along the way.

“He’s really fast,” Kittle said. “He was fantastic.”

[RELATED: Why Andrews had to troll Bosa in Ravens' win vs. 49ers]

Mostert received a greater opportunity in recent weeks with leading rusher Matt Breida out of action for three games with an ankle sprain. Mostert already has a career-best 539 yards and three touchdowns with a gaudy 5.9-yard average on the season.

“You got to have that mindset to go in there and play ball,” Mostert said. “I don’t really look at it, as I’m not right now. I look at it as it’s another opportunity for me to go out and showcase what I can do and be a better person and better player for my team.”