SANTA CLARA, Calif. (AP) — Jimmy Garoppolo led one final scoring drive in the closing seconds to cap a fantastic first home start, Robbie Gould kicked a game-winning 45-yard field goal as time expired, and the San Francisco 49ers topped the Tennessee Titans 25-23 on Sunday.

Garoppolo threw for a career-high 381 yards and a touchdown during a dominant day to give the 49ers (4-10) a three-game winning streak in a lost season. And Tom Brady’s former backup showed he could do it at home as well as on the road — and against a playoff contender, no less — outdueling Marcus Mariota down the stretch as the teams traded field goals.

Gould kicked three of his six field goals over the final nine minutes: 50, 48 and 45 yards and has now gone 20 consecutive without a miss. Gould put the Niners out front on a 48-yarder with 3:08 remaining. Mariota then drove the Titans (8-6) to a lead as Ryan Succop kicked a 50-yard field goal with 1:07 to play, then Garoppolo and the San Francisco offense got one last shot.

Marquise Goodwin made 10 catches for 114 yards and Garoppolo completed 31 of 43 passes to go over 300 yards passing for the second straight game after last week’s win at Houston. Mariota put Tennessee ahead on an 8-yard touchdown pass to Rishard Matthews early in the fourth as the Titans rallied back from an early 13-point deficit.

Tennessee came out of intermission a new team, totaling 22 offensive plays to San Francisco’s five in the third quarter.

Mariota threw a 4-yard TD pass to former 49er Delanie Walker late in the first half to keep the Titans close. The Titans played a second straight road game against the NFC West after losing last week to the Cardinals and staying in Arizona for the week of practice. Their first visit to Levi’s Stadium — Tennessee last played the Niners on the road at Candlestick in November 2009 — began slowly, the team’s second straight week playing a stadium for the initial time.

Mariota, in the midst of one of the worst stretches of his three-year career, threw for 241 yards completing 23 of 33 passes. Tennessee’s typically tough defense was a far cry from that dominant unit in the first half.

Last week, the Titans allowed only four field goals, the second time this season they’d done so. From Week 5, Tennessee had been allowing only 295.1 yards per game. Titans CB Logan Ryan sustained an ankle injury in the second quarter.

The Titans host the Rams next Sunday and are at home for the the final two games of the regular season.

___