Buffalo nearly did enough to stave off New England’s claim to an 11th straight AFC East title.

Josh Allen and the Bills’ defense couldn’t finish the job.

A late Patriots touchdown and an Allen-led drive that stalled in the red zone ended Buffalo’s hopes of winning its first division crown since 1995.

“We’ve got to find a way to get over that hump,” Allen said after New England’s AFC East-clinching 24-17 win on Saturday. “We were playing to put ourself in position where we could potentially win it, but they played well today and hats off to them.”

Buffalo drove to the 8-yard line after a 25-yard pass by Allen to Cole Beasley with just over two minutes remaining. Allen then took a 1-yard loss and threw an incomplete pass.

Allen was sacked for a 6-yard loss on third-and-goal before throwing a jump ball to Beasley in the end zone that was broken up.

“When we get it down there, we’ve got to get in the end zone. There’s no doubt about that,” said Allen, who finished 13 of 26 for 208 yards and two touchdowns. “I just tried to make a play and give somebody a chance.”

Buffalo’s defense gave the team plenty of chances early on in a close game that mirrored the first meeting with the Patriots, a 16-10 loss at home on Sept. 29.

In that game, the Bills held Tom Brady to 150 yards and a season-low 45.9 passer rating. This time, Brady passed for 271 yards and a 111 rating, his second-highest of the season.

“It’s hard to win when you’ve got Tom Brady on the field as many times as he was, and we didn’t do a good enough job just fundamentally in some areas,” Buffalo coach Sean McDermott said. “I thought some things were up to our standards, and others certainly weren’t.”

Buffalo led 17-13 after Allen connected with John Brown for a season-long pass of 53 yards with 7:34 to play in the third quarter and led 17-16 after a New England field goal heading into the fourth quarter.

Brady then led a seven-play, 59-yard drive — including a 30-yard pass to star receiver Julian Edelman — that ended in Rex Burkhead’s 1-yard, go-ahead touchdown rush and a 2-point conversion to Edelman with 5:06 remaining.

“We knew we had to finish the game. That’s the greatest quarterback to ever play the game, and we knew they were gonna come back and try to strike,” Bills safety Jordan Poyer said. “They just made more plays than us today.”

With a win, the Bills would have given themselves another week’s worth of hope to win the division. Buffalo would have needed a win over the New York Jets next week and a Patriots’ loss to the Miami Dolphins to take the crown.

Instead, they are 10-5 and will finish second in the AFC East — but still have a second playoff berth in three seasons to look forward to.

And if another matchup with New England is on the horizon, the Bills believe they’ll be ready.

“We’re confident that we can beat any team,” Buffalo offensive tackle Dion Dawkins said. “But hopefully third time is the charm.”