Gould's 20th consecutive successful field goal came 67 seconds after Ryan Succop had nailed a 50-yard field goal to give the Titans a 23-22 lead.
The win was the 49ers' third in a row since promoting Jimmy Garoppolo to starting quarterback.
The ex-New England Patriot passed for 381 yards and a second-quarter touchdown to tight end Garrett Celek.
The loss was the second in a row for Tennessee (8-6) and dropped the Titans into a tie with Buffalo (8-6) and Baltimore (8-6) for the two AFC wild-card positions.
Gould accounted for all the San Francisco scoring other than Garoppolo's touchdown pass. His field goals came from 38, 48, 28, 50, 48 and 45 yards.
Wide receiver Marquise Goodwin had 10 catches for 114 yards for the 49ers (4-10), who won at home for just the second time this season.
Marcus Mariota threw for 241 and two touchdowns for the Titans, who lost last week at Arizona and were playing their final road game of the season.
Mariota threw touchdown passes to tight end Delanie Walker and wide receiver Rishard Matthews as the Titans rallied from a 16-3 deficit to take 20-16 and 23-22 leads in the fourth quarter.
Matthews finished with 95 receiving yards on six catches.
Succop made three field goals, from 40, 31 and 50 yards.
Gould's fifth field goal had given the 49ers a 22-20 lead with 3:08 to play. It capped a 49ers drive that began with a 54-yard pass from Garoppolo to rookie Kendrick Bourne and nearly ended when Trent Taylor fumbled into the end zone after catching a pass.
Offensive guard Laken Tomlinson saved the game for the 49ers when he recovered in the end zone, and even though the score was negated by an offensive pass-interference penalty, San Francisco retained possession, allowing Gould to get a shot at the go-ahead field goal.
Mariota then drove the Titans to their go-ahead score with 1:07 left.
The Titans trailed 16-10 at halftime, but they marched down the field for scores on each of their first two drives of the second half. Tennessee took its first lead of the game on Mariota's second touchdown of the day, an 8-yarder to Matthews with 13:31 left in the game.
The 49ers drove to the Tennessee 16 on their next possession, but Garoppolo lost 6 yards when he caught his own pass that had been deflected and another 10 when sacked on third down by Titans linebacker Wesley Woodyard.
They had to settle for Gould's fourth field goal of the game, a 50-yarder that made cut Tennessee's lead to 20-19 with 8:27 to go.
The 49ers dominated the first 28 1/2 minutes, building a 16-3 lead on the strength of Garoppolo's 18-for-26, 189-yard first half.
However, three of San Francisco's four scoring drives resulted only in field goals, allowing the Titans to stay within striking distance.
The Titans, limited to 57 yards to that point, went 79 yards in just six plays in their rally-igniting drive to Walker's touchdown catch that made it a 16-10 game at halftime.
NOTES: The Titans (8-6) fell two games behind Jacksonville (10-4) in the AFC South with two games to play. The two leaders meet at Tennessee on the final weekend of the season. ... The 49ers also play the Jaguars. That game will complete San Francisco's home schedule next week. ... Niners QB Jimmy Garoppolo had to change helmets during the first drive of the game because of communication issues. The 49ers had to use a timeout just two plays into the game because of the problem.