Hours after the game, the 49ers announced that Tomsula was fired, ending his 49ers reign after one season that ended with a 5-11 record.
Before the news broke, Tomsula was asked if he thought he deserved to keep his job.
"You're a coach," Tomsula said. "You always think that. How you think about that and those things is irrelevant."
The 49ers won the toss and took the kick in overtime, but they stalled at the 50 and punted. St. Louis (7-9) marched to the 49ers 30-yard line, but cornerback Dontae Johnson blocked Greg Zuerlein's 48-yard field goal attempt.
San Francisco quickly marched into Rams territory, and on second-and-10 from the 38, quarterback Blaine Gabbert hit wide receiver Quinton Patton on a 33-yard pass to the 5.
Dawson came on to kick the game-winner.
Free safety Eric Reid said it was important for the 49ers to end the season with a victory.
"With a season like this, that's all you can play for," Reid said. "You're not playing for anything else. We're all going home now, but it's nice to have a win. It's always good to win, no matter if you're 0-16 or 16-0."
Running back DuJuan Harris, making his first start as a 49er, rushed for 67 yards on 16 carries and caught eight passes for 86 yards. Wide receiver Anquan Boldin caught five passes for 71 yards and a 33-yard touchdown.
Quarterback Case Keenum completed 22 of 37 passes for 231 yards for the Rams, whose three-game winning streak ended.
"It hurts a lot," Rams wide receiver Tavon Austin said. "They played hard today, and we did, too. We have to close it out. That's been our problem the whole year. Next year we'll be closing out a lot of these games."
The Rams were without star rookie running back Todd Gurley, who missed the game with an injured foot and finished the season with 1,108 rushing yards. Tre Johnson started in his place and rushed for 44 yards on 18 carries.
The Rams built a 16-10 halftime lead, but San Francisco opened the second half with a 12-play, 70-yard scoring drive capped by Dawson's 28-yard field goal. Gabbert's 44-yard deep strike to wide receiver Bruce Ellington gave the 49ers a first down at the St. Louis 26.
The 49ers marched to the Rams 8 late in the fourth quarter and faced third-and-1. Gabbert's pitch was left of Harris, who fell on the ball for a 12-yard loss. The 49ers settled for Dawson's 38-yard field goal, pulling even at 16-16 with 4:28 to play.
"I'm just so proud of the guys, the way we fought," Gabbert said. "There were a lot of ups and downs, adversity."
The 49ers forced a quick punt and drove to the Rams' 37. But facing fourth-and-4, San Francisco passed up a chance for Dawson to try a 54-yard field goal and punted.
The Rams had a chance to finish .500 for the first time since 2006 for the first time since 2004. Instead, they lost to their struggling NFC West rival and finished with a losing record.
"It's the last game of the season, and it leaves a bad taste in your mouth," Keenum said.
According to his players, Tomsula didn't talk to them before or after the game about his future with the team.
"It's about the game today," 49ers linebacker NaVorro Bowman said. "I've been with Jimmy my whole career. I love Jimmy. It's always been a good time with him. But today we won a game, and let's give him some praise for that. Let's not talk about the rumor or whatever was said."
The Rams struck first, taking a 3-0 lead on Zuerlein's 33-yard field goal with 8:11 left in the first quarter, capping a 72-yard drive. Keenum hit wide receiver Kenny Britt on a 54-yard strike to the San Francisco 33, setting up the field goal.
The 49ers countered with Gabbert's 33-yard touchdown pass to Boldin with 14:52 left in the half, giving them a 7-3 lead.
Dawson increased San Francisco's lead to 10-3, kicking a 26-yard field goal with 9:03 remaining in the half.
Zuerlein cut San Francisco's lead to 10-6, capping a 66-yard drive with a 32-yard field goal with 2:43 left before intermission.
Three plays later, Rams defensive end Eugene Sims intercepted a tipped Gabbert pass and returned 42 yards to the San Francisco 3. That set up Mason's 4-yard touchdown run on a run-pass option, putting the Rams ahead 13-10 with 1:31 left in the quarter.
Zuerlein connected again late in the half, this time from 44 yards, increasing the Rams' lead to 16-10.
NOTES: 49ers nickel CB Jimmie Ward made his first career start at strong safety, replacing Jaquiski Tartt (knee), who was inactive. Ward made 10 tackles, two of them for losses. ... 49ers DE Quinton Dial (back strain) was inactive. Rookie Arik Armstead started in his place. ... Rams WR Nick Toon, who was signed off the practice squad earlier in the week, suited up against the 49ers. ... 49ers RB Mike Davis (broken hand) was active Sunday after missing seven games while on injured reserve/designated for return. He gained 34 yards on 10 carries.