MINNEAPOLIS — Sooner or later, Jimmy Garoppolo was going to lose a game.

This was his toughest test yet as San Francisco's starting quarterback, facing a fierce Minnesota defense that refused to let him pass.

With two touchdown passes by Kirk Cousins in his debut and three interceptions of Garoppolo in the second half, the Vikings had enough to hold on for a 24-16 victory over the 49ers in the season opener on Sunday to stick Garoppolo with his first loss in eight games as an NFL starter .

"None of us did good enough to win today, especially on offense," coach Kyle Shanahan said.

Garoppolo won twice for New England in 2016 during Tom Brady's suspension. He guided the 49ers to five straight wins to finish 2017 after he arrived in a trade with the Patriots and the team had fallen to 1-10, but the NFL schedule this year did his streak no favors.

The Vikings used their star-stacked defense to finish 13-3 and reach the NFC championship game last season, leading the NFL in fewest yards and points allowed and third down conversions against.

Minnesota's U.S. Bank Stadium is one of the loudest places in the league for opponents to play, too, and the crowd was cranked up on every one of San Francisco's 13 third downs. The 49ers converted five.

"We knew it was going to be a tough challenge with the environment, going against a tough team. They stood up to everything we thought they would, but with all the things that went bad we still had a shot at the end there," Garoppolo said. "Just a tough way to end it."

The 49ers' defense forced three straight three-and-out possessions by the Vikings in the fourth quarter, giving Garoppolo an opportunity for the comeback. After the first of those punts, with Minnesota leading 24-13, Garoppolo's pass for Dante Pettis sailed past the rookie and to Xavier Rhodes for a one-handed interception .

With San Francisco trailing 24-16, Harrison Smith snagged Garoppolo's overthrow for Trent Taylor at the 29-yard line to seal the game.

"You have to force it, but you have to be smart about when to force it I guess," Garoppolo said. "It's tough backed up like that."

In the third quarter, when Kendrick Bourne lost his footing on a sideline route, Garoppolo's pass sailed straight to Vikings rookie Mike Hughes for a 28-yard interception return for a touchdown and a 17-3 lead. Garoppolo was particularly agitated on the sideline. When asked if he was upset with Bourne, he didn't deny it.

"What are you supposed to say at that point? It's an 'it is what it is' kind of thing. It was both of our faults, but whenever you throw an interception it's always on the quarterback," said Garoppolo, who finished 15 for 33 for 261 yards.

With three backups already on the inactive list, the 49ers lost two right guards to left foot injuries during the game. After Mike Person (second quarter) and Joshua Garnett (third quarter) went out, rookie right tackle Mike McGlinchey had to slide over for the first action at guard of his life as Gary Gilliam entered at right tackle.

Wide receiver Marquise Goodwin, who found a groove with Garoppolo down the stretch to finish with a team-leading 962 yards, hurt his right quadriceps in the first quarter and didn't return.

While Cousins twice connected on tight-window throws for touchdowns for the Vikings, most of Garoppolo's similar throws in traffic went Minnesota's way. Trae Waynes ripped the ball away from Pettis as they both fell to the turf in the end zone at the end of a deep play in the second quarter.

So Garoppolo's performance certainly wasn't all bad.

He completed two third-and-long passes during a 14-play, 73-yard possession in the second quarter that reached the 1, only to watch Linval Joseph and Harrison Smith force Alfred Morris to lose a fumble on second-and-goal with 2:18 left before halftime and the Vikings leading 10-3.

On his first snap after the pick-six by Hughes, Garoppolo found fullback Kyle Juszczyk wide open along the right sideline for a 56-yard gain that put the 49ers in range for the second of Robbie Gould's three field goals.

After the Vikings took a 24-6 lead late in the third quarter, Garoppolo directed a seven-play, 75-yard drive to whittle the deficit back to 11 points. With the pocket collapsed in front of him, Garoppolo spun out in a 360-degree turn left and zipped an off-balance throw to Pettis in the back of the end zone for a 22-yard touchdown .

Highlighted by tight end George Kittle's five catches for 90 yards, there was enough production by the 49ers to take some positives into their home opener against Detroit next week.

"We were rolling there toward the end," Kittle said. "It didn't end the way we wanted, but I feel like we definitely had some momentum going, and if we can do that we'll be a pretty good offense."