The way Josh Allen and Buffalo carved up San Francisco’s defense, the 49ers had almost no margin for error on offense if they wanted any chance to beat the Bills.

With the offense far from perfect, the Niners were dealt a 34-24 loss on Monday night and now have almost no margin for error if they have any hopes of making it back to the playoffs to defend their NFC title.

San Francisco (5-7) will likely need to win its final four games starting with Sunday’s matchup against Washington at the Niners temporary home in Arizona, and get some help from other teams.

“We really feel like we can be a better football team. So, we’re all frustrated,” quarterback Nick Mullens said. “But we know that this loss isn’t going to break us. There’s a lot of football left to be played. We get more opportunities and ready to get back to work for those opportunities. This team is tough, as tough as it gets. We’re not going to back down. We embrace the challenge. We love the challenge, and that’s what we’re going to work and strive for.”

The Niners have faced many challenges with a string of injuries that have sidelined several key starters and the forced move to Arizona after new COVID-19 protocols in Santa Clara County banned them from practicing or playing games at their facility and stadium.

Coach Kyle Shanahan and the players downplayed the impact the move had on the performance against the Bills, pointing to defensive breakdowns against Allen and a few key mistakes on offense.

“We needed to play our best and I think that we were very close to doing it,” Shanahan said. “We just had a few things that didn’t keep us out on the field and when you do that versus an offense and a quarterback like that who’s playing the way they are and you don’t get it back for a while, the game gets away from you.

"I think we needed to keep matching them and it was frustrating because I believe that we were capable of that. We had our chances, which I think you saw at times, but we had to do it every time and we didn’t get that done.”

WHAT’S WORKING

Run defense. San Francisco did a good job bottling up Buffalo running back Devin Singletary and also didn’t allow Allen to scramble. The Niners held the Bills to 81 yards on 27 carries, but it didn’t end up mattering because of how easily they moved the ball through the air.

WHAT NEEDS HELP

Slot cornerback. Injuries at slot cornerback proved costly to the 49ers, who struggled to slow down Cole Beasley, who had nine catches for 130 yards and a TD. Starter K’Waun Williams is out with an ankle injury and backup Jamar Taylor went down with a season-ending knee injury last week. Emmanuel Moseley had filled in, but missed this game with a hamstring injury and Dontae Johnson struggled with the crafty Beasley.

STOCK UP

Dion Jordan. On a night when the Niners struggled to generate any consistent pass rush, Dion Jordan managed to provide the lone sack. Jordan hasn’t made much of an impact since having a sack in his San Francisco debut in Week 3 against the Giants, but was one of the few 49ers defenders who even got a hit on Allen this week.

STOCK DOWN

Pass defense. While the problems dealing with the slot can be explained by injuries, the rest of the secondary struggled as well. Allen completed 32 of 40 passes for 375 yards and four TDs, joining Hall of Famer Dan Fouts as the only QBs with at least 30 completions, 375 yards and four TDs against the 49ers. Usually reliable outside cornerbacks Richard Sherman and Jason Verrett both struggled and the Bills exploited coverage breakdowns for big plays.

INJURED

DT D.J. Jones left with a sprained ankle. ... OL Tom Compton had a concussion.

KEY NUMBER

2. The 49ers turned the ball over twice on interceptions by Nick Mullens. It’s the sixth straight game that San Francisco has had at least two giveaways, the longest active streak in the NFL and longest for the team since an eight-game streak in 2008.

NEXT STEPS

The Niners play Washington on Sunday in Arizona.

More AP NFL: https://apnews.com/NFL and https://twitter.com/AP_NFL