– 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 TD 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 36-yard field-goal attempt 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 victory 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."

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.