CHICAGO (AP) The Chicago Bears had just taken a late lead when San Francisco 49ers coach Jim Tomsula delivered the message to Blaine Gabbert.
He told his quarterback to enjoy the moment. Gabbert owned it, instead.
Gabbert threw a 71-yard touchdown pass to Torrey Smith in overtime after running for the tying TD late in regulation, lifting the struggling 49ers to a 26-20 victory over the Bears on Sunday.
''You get opportunities like that,'' Tomsula said. ''You got to enjoy them. That's why they play the game. All of these players in the NFL are amazing athletes. Amazing individuals. You get in a moment like that. Enjoy it. Savor it.''
Tomsula's pep talk came right after Chicago's Ka'Deem Carey ran for a touchdown in the closing minutes of regulation.
Gabbert answered with a big TD run and then won it with that long pass in OT after the Bears' Robbie Gould missed a field goal at the end of regulation.
''You really saw kind of the peaks and valleys of NFL football right there,'' Gabbert said.
The Bears (5-7) had just gone three-and-out after forcing a punt by San Francisco to start the extra period.
On the first play of the 49ers' second possession, Gabbert found a wide-open Smith along the left sideline, giving San Francisco (4-8) a surprising win over a team that had jumped into playoff contention.
''It was set up by all the throws we had underneath early on in the game, all the runs we ran out of that formation,'' Gabbert said. ''It worked perfectly. Torrey did a great job tracking the ball in the air and using his speed to outrun everybody.''
All that happened after a wild finish in regulation.
The Bears took a 20-13 lead on Carey's 4-yard run with 3:32 left, only to let it disappear and then blow a chance to win the game as time expired.
Gabbert scrambled 44 yards untouched through the middle for his first career touchdown run with 1:42 left, after some encouragement from Tomsula.
If that wasn't bad enough for Chicago, the Bears wasted a huge opportunity after Deonte Thompson returned the kickoff 74 yards to the 28. The Bears had the ball at the 17 when they called on the usually reliable Gould, and at that point, linebacker NaVorro Bowman could sense the dread on the sideline.
''We had this feeling a few games (where) we played well and fell a little short,'' he said. ''That same kind of emotion and feeling came back. We're right there. And I think today showed what we've been trying to get to all the players - just keep fighting no matter what's happening in the game.''
Gould, who missed a 40-yard attempt in the third quarter, booted a 36-yarder wide left as time expired.
''I just got quick on both of them and rushed them, and hurried them,'' said Gould, who turned 34 Sunday. ''They were both probably the worst kicks I've had all year.''
Gabbert, who took over for Colin Kaepernick last month, completed 18 of 32 passes for 196 yards and a touchdown. He also ran for 75 yards and his score.
Smith had two catches for 76 yards, and Jimmie Ward returned his first career interception for a touchdown, helping the 49ers snap a two-game losing streak and secure their first road win. They were 0-5 away from home.
Chicago's Jay Cutler was 18 of 31 for 202 yards with that interception. Alshon Jeffery had 85 yards receiving and Matt Forte ran for 84 and a touchdown, but for the second time in three games, the Bears missed a chance to reach .500. They also fell to 1-5 at home.
Chicago followed up a rare win at Green Bay on Thanksgiving with a gut-wrenching loss against a team both coordinators probably would have loved to beat.
Defensive coordinator Vic Fangio and offensive coordinator Adam Gase interviewed for the 49ers' head coaching job that went to Tomsula following Jim Harbaugh's departure after last season. Gase wound up following Fox from Denver, and Fangio moved to Chicago after overseeing one of the league's top defenses the past four years in San Francisco.
''Offensively we didn't play that great in Green Bay either,'' Cutler said. ''That's kind of the facts. Today we didn't play exceptionally well either. Offensively we've got a lot of work to do.
NOTES: 49ers LB Aaron Lynch left the game with a concussion in the third quarter. ... This was San Francisco's first regular-season win at Chicago since 1974. The 49ers did beat the Bears at Soldier Field in the conference championship game at the end of the 1988 season. ... The 49ers were 7 of 16 on third downs after going 0 for 9 against Arizona.
AP NFL website: www.pro32.ap.org and http://twitter.com/AP-NFL