CHICAGO — Robbie Gould pumped his right arm. He screamed at the Chicago sideline. Kicking the winning field goal sure made it a sweet return to Soldier Field.

Gould nailed a 24-yarder in the closing seconds, Jimmy Garoppolo threw for 293 yards in his first San Francisco start, and the 49ers beat the Chicago Bears 15-14 on Sunday.

Gould made all five field goals — none longer than 35 yards — in his first appearance at Soldier Field since Chicago cut him prior to the 2016 opener. The Bears’ all-time leader in points and field goals made, he let it all out after he booted the winner right down the middle.

“I wanted this one really bad,” Gould said. “I downplayed it all week for my own peace of mind, to be honest with you. I’m just happy it went this way.”

Garoppolo was solid in his first start since the 49ers (2-10) acquired him from New England before the trade deadline in October. The suburban Chicago and Eastern Illinois product completed 26 of 37 passes with an interception. And the 49ers picked up the win after losing their first five road games.

Garoppolo grew up a Bears fan but never attended an NFL game until he entered the league, so this was quite an experience.

“I tried to say all week that it was just a normal game, but obviously, I’d never come back to Chicago like this,” Garoppolo said. “It’s exciting. I had a ton of people here. It was one of the more fun games I’d been a part of.”

Marquise Goodwin had eight catches for 99 yards. Trent Taylor added 92 yards receiving, including a 33-yarder that kept the winning drive going even though he was sick to his stomach.

Chicago (3-9) dropped its fifth straight, and coach John Fox fell to 12-32 in three seasons with the Bears.

“It was hard to even talk to the team after this loss,” he said.

Then again, what is there to say? The Bears are wrapping up their fifth straight season without a winning record and will finish below .500 for the fourth year in a row. They went from getting pounded by a championship contender at Philadelphia to losing to one of the league’s worst teams.

Mitchell Trubisky was 12 of 15 for 102 yards and a touchdown. Not exactly the bounce-back performance he wanted coming off a rough outing against the Eagles.

“I mean, there’s two ways to handle it: positively and negatively,” Trubisky said. “You put your head down and come up here and sound like a loser. Or you can just believe in what you know, go back to work and just know the guys in the locker room have your back and have their back, and have the faith that it’s going to turn around.

Tarik Cohen returned a punt 61 yards for a touchdown. That made him the first NFL rookie with rushing, receiving, passing and punt return TDs in a season since Gale Sayers in 1965.

Garoppolo showed his poise on the winning drive, lSan Francisco from its 8 to the Chicago 6.

His 33-yard pass to Taylor on third down put the ball on the Bears 18 with two minutes left and helped set up Gould’s big kick.

“(Garoppolo) never seems too high, never seems too low, which is what in a quarterback,” coach Kyle Shanahan said. “He kept that throughout the game. ... The guy never changed, which is what you want to see. It allows you to overcome mistakes.”

MISSED CHANCES

The 49ers dominated in total yards (388-147) and time of possession (38:47-21:13). But they committed eight penalties, several near the end zone. That helped explain why they failed to score touchdowns on five trips inside the 20.

FAMILY LESSONS

In another twist to the homecoming story, Gould said his father-in-law taught Garoppolo in high school.

INJURIES

49ers: Starting RT Trent Brown (shoulder) started after being listed as questionable. S Adrian Colbert also started after missing last week’s 24-13 loss to Seattle following thumb surgery.

Bears: LB Pernell McPhee suffered a shoulder injury on the game’s opening drive. ... DE Mitch Unrein (knee) was hurt in the second quarter. ... RG Kyle Long (shoul out the second half. ... K Cairo Santos tweaked his groin. ... LG Josh Sitton started after being listed as questionable because of a concussion. ... S Adrian Amos (hamstring) and his backup Deon Buswere inactive.