ORCHARD PARK, N.Y. (AP) — Not lost amid the euphoria and relief following the Bills beating the Chiefs in a much-anticipated early season showdown of the AFC’s two top teams was Buffalo general manager Brandon Beane’s impact on the outcome.

As each pivotal play unfolded in the closing minutes of Buffalo’s 24-20 nail-biting victory, Beane’s influence was apparent in having transformed a dysfunctional franchise — seven coaches and a 17-year playoff drought spanning 2000 to ’17 — into a Super Bowl contender.

“You try to identify what you need to improve on your team, Brandon does a great job with that,” coach Sean McDermott said following the win.

“Then acquiring those players to help you factor in these games in the way they factored, it was good to see.”

McDermott was specifically referencing the moves made this offseason to muscle up Buffalo’s defensive front, highlighted by the free-agent addition of Von Miller.

And yet, he could just as well have been discussing Beane’s entire body of work.

In five-plus seasons, the first-time GM purged the franchise of under-performing and over-paid players by rebuilding a roster that currently features 30 members drafted by Buffalo, including the most important pick of Josh Allen in 2018, and filled other needs through trades and free agency.

All of it was on display on Sunday, when Buffalo (5-1) gained the inside track to finishing first in the AFC by knocking off the Chiefs (4-2) in a setting where the Bills’ past two seasons have ended with playoff losses.

When Allen, the once-maligned first-round draft pick out of Wyoming, wasn’t once again hurdling opponents (safety Justin Reid, this time), he was threading a perfect pass to Dawson Knox for the go-ahead touchdown with 1:04 remaining.

There was Stefon Diggs, who arrived in Buffalo with a mercurial reputation following a trade with Minnesota in 2021, leading the way with 10 catches for 148 yards and a touchdown.

How about Taron Johnson, a fourth-round pick out of Weber State in 2018, sealing the win with his latest clutch interception. Two of Johnson’s previous four interceptions were returned for touchdowns, including a 101-yarder in a 17-3 win over Baltimore in the AFC divisional playoff round in the 2020 season.

And let’s not forget Miller.

The NFL’s active leader in sacks provided the game-changing plays the Bills lacked in squandering a three-point lead over the final 13 seconds of a 42-36 overtime loss to the Chiefs in the divisional round of the playoffs in January.

Aside from two sacks, Miller’s pressure of Patrick Mahomes led to the Chiefs quarterback hurrying the throw Johnson intercepted.

The 33-year-old Miller has a team-leading six of Buffalo’s 19 sacks, which rank tied for fourth in the NFL entering Monday. And he’s part of a defense which has allowed the second-fewest yards and fewest points overall entering Monday.

Beane’s commitment to improve Buffalo’s front went beyond Miller, with the Bills also adding defensive tackles Jordan Phillips, Tim Settle, DeQuan Jones and end Shaq Lawson this offseason. He did so after Buffalo was inconsistent against the run and its middling pass rush managed 42 sacks, with 14 of them coming in the final two games against the Jets and Atlanta.

The inability to pressure opposing quarterbacks was apparent in the playoff loss to the Chiefs.

Former Bills defensive end Jerry Hughes was a half-step from getting to Mahomes, when the quarterback competed a 25-yard pass to Travis Kelce to set up Harrison Butker’s game-tying 49-yard field goal as time expired.

Beating the Chiefs on Sunday helps relieve some of the sting.

“Obviously, there were still some bad memories from this place last year,” Knox said. “So it was nice to be able to wipe that from our minds and get a win and keep moving on.”

What’s working

Clutch plays. The Bills went from losing seven straight games decided by one score to winning their past two, including overcoming a 17-point deficit to beat Baltimore 23-20, with both games decided in the final two minutes.

What needs help

Fumbles. The Bills have lost six fumbles, the second most in the NFL behind New Orleans (seven) entering Monday. Two of those fumbles have come in the red zone after Allen and receiver Isaiah McKenzie misplayed a short pitchback at the Chiefs 13.

Stock up

S Jordan Poyer. Cleared to play but not cleared to fly because of the aftereffects of a punctured lung, the starter had four tackles and played all 67 defensive snaps while making the 14-hour, near 1,000-mile to Kansas City in a van rented by the team.

Stock down

McKenzie. Aside from his share of blame for the fumble credited to Allen, the slot receiver caught just two of five passes thrown his way for 9 yards.

Injuries

Starting RT Spencer Brown did not return after hurting his ankle.

Key number

12 — Number of times the Bills have started a season 5-1 or better. They’ve made the playoffs 10 times, with the only exception coming with a 7-9 finish in 2008.

Next steps

Finally enjoy a bye week coming off a win. Buffalo entered its past two bye weeks following losses decided in the final minute: a 34-31 loss at Tennessee last year, and a 32-30 loss at Arizona in 2020. Next up is a prime-time home game against Green Bay on Oct. 30.