SANTA CLARA, Calif. (AP) — Richard Sherman wasn’t in a celebratory mood after his first win with the San Francisco 49ers.

That’s what allowing two fourth-quarter touchdowns and needing a favorable call by the officials just to avoid blowing a 17-point lead will do.

“A win’s a win but it feels like a loss,” Sherman said following San Francisco’s 30-27 victory over the Detroit Lions on Sunday. “We played like crap down the stretch. We have to execute down the stretch and play better. It’s a good lesson for a young team that we needed. It’s a humbling lesson. Thank goodness we got a win out of it.”

The 49ers (1-1) broke out to a 30-13 lead behind two touchdown passes from Jimmy Garoppolo and a 66-yard TD run by Matt Breida only to see most of it evaporate on a pair of TD passes by Matthew Stafford in the fourth quarter for the Lions (0-2).

That’s when the biggest play happened with San Francisco facing a third-and-2 near midfield. Garoppolo threw a quick out to Breida, but Tracy Walker stepped in front and intercepted the pass, returning it to the San Francisco 7.

Quandre Diggs was called for holding George Kittle on the other side of the field, giving the 49ers a reprieve.

“I didn’t see it, but it doesn’t matter,” Detroit coach Matt Patricia said. “That’s the way the game is being called all the way across the board. We just can’t do it, make plays and then the penalties.”

The 49ers managed to run off more time and Stafford didn’t get the ball back until he had 1:08 to go and the ball at his own 16. Detroit moved the ball to the 39 before three straight incompletions led to a turnover on downs.

But a 49ers team that was happy to get any kind of win last year after an 0-9 start was far from satisfied.

“It’s a different mindset than last year,” Garoppolo said. “Last year if we got a win, we were happy about it. Now, you kind of progress as a team. I think our guys are growing and learning like that. When you have a chance like we had to blow them out and take advantage of that stuff, we didn’t. It’s just little things like that we need to clean up.”

Here are some other takeaways from the game:

UNDER PRESSURE

The Lions managed to put heavy pressure on Garoppolo even though top pass rusher Ezekiel Ansah missed the game with a shoulder injury. Detroit finished with six sacks, including two apiece from Jarrad Davis and Devon Kennard. Three of the sacks came in the red zone, forcing San Francisco twice to settle for field goals.

“I’ve got to get the ball out faster,” Garoppolo said. “Help those guys out, make it easy, get our offense in to more of a rhythm and just take what they’re giving me type of thing.”

BREIDA’S DAY

The 49ers faced questions at running back when Jerick McKinnon went down with a season-ending knee injury a week before the start of the season. Breida showed he can handle some of that load by rushing for 138 yards on 11 carries and catching three passes for 21 yards. His TD run was San Francisco’s longest since Colin Kaepernick had a 90-yarder against the Chargers on Dec. 20, 2014.

“You have to make the most of your opportunities,” Breida said.

EJECTION

Detroit running back LeGarrette Blount was ejected in the third quarter. Blount took exception to Elijah Lee pushing Stafford as he stepped out of bounds. Blount was standing on the sideline right in front of the play and went on the field and pushed Lee. Blount was assessed a personal foul and ejected.

“He knows better,” Patricia said. “He knows that he can’t do that.”

REPEAT RETURNS

For the second straight week, the Lions allowed a long return in the kicking game. D.J. Reed’s 90-yard kickoff return to start the second half set up San Francisco’s second TD of the game. Last week, Andre Roberts scored on a 78-yard punt return for the Jets.