The Miami Dolphins almost squandered their lead against the Buffalo Bills in embarrassing fashion, but they held on to beat their division rival, 21-19, to sit atop the AFC East at 3-0 this season.

Dolphins punter Thomas Morstead was pinned in his end zone when he punted a ball directly off the backside of his own player, and it caused a safety as the ball ricocheted behind the end line to make it 21-19.

This was a crucial play because the Dolphins had just stopped a Buffalo push to take the lead.

CLICK HERE FOR MORE SPORTS COVERAGE ON FOXNEWS.COM

Josh Allen scrambles and throws

Quarterback Josh Allen of the Buffalo Bills looks to pass against the Miami Dolphins at Hard Rock Stadium in Miami Gardens, Florida, on Sept. 25, 2022. (Megan Briggs/Getty Images)

The Dolphins came up big on their own 2-yard line, where Bills quarterback Josh Allen couldn’t find a receiver in the end zone, throwing incomplete passes to Stefon Diggs and Isaiah McKenzie on third and fourth down, respectively.

Because the "Butt Punt" didn’t end up in a loss for the Dolphins, the turning point of the game in this one was a missed field goal by Bills kicker Tyler Bass, a 38-yard attempt that went wide left.

The Dolphins took over and only needed six plays to go 72 yards for the score. Chase Edmonds busted it up the gut for three yards and made it 21-17.

DOLPHINS' TUA TAGOVAILOA APPEARS WOOZY AFTER TAKING HIT, BRIEFLY LEAVES GAME WITH HEAD INJURY

Dolphins quarterback Tua Tagovailoa finished the game with 186 yards on 13-of-18 passing with a touchdown and no interceptions thrown.

He also had a very scary moment in the first half where he took a hit with his helmet smacking the ground. He got up wobbling and had to be medically evaluated, but he ended up playing the second half.

Teddy Bridgewater talks to Mike McDaniel

Quarterback Teddy Bridgewater (5) speaks with head coach Mike McDaniel of the Miami Dolphins during the first half against the Buffalo Bills at Hard Rock Stadium in Miami Gardens, Florida, on Sept. 25, 2022. (Eric Espada/Getty Images)

Allen, on the other hand, did very well in this game as he was tasked with 63 pass attempts. He completed 42 of them for 400 yards and two touchdowns. But in the end, the passes he needed to complete didn’t work out.

Allen’s first drive of the day was a 10-play, 75-yard masterpiece that saw Devin Singletary getting into the end zone on a two-yard pass.

BILLS' MICAH HYDE TO MISS REST OF NFL SEASON WITH NECK INJURY, PLACED ON IR: REPORT

But after a nice stop to force a Dolphins’ punt, Allen was strip-sacked to set up an Edmonds score, his first of the game, to tie the game at seven.

Both teams would trade touchdowns to end the first half at 14 apiece. The Bills' McKenzie got into the end zone as well as Dolphins wideout River Cracraft. 

The leading receiver in this one was Jaylen Waddle, who had just four catches for 102 yards. After collecting three touchdowns against the Tennessee Titans last week, Diggs couldn’t find the end zone.

Tua Tagovailoa looks to throw

Quarterback Tua Tagovailoa of the Miami Dolphins eyes his receiver during the game against the Buffalo Bills at Hard Rock Stadium in Miami Gardens, Florida, on Sept. 25, 2022. (Megan Briggs/Getty Images)

Buffalo will look to bounce back next week against the Baltimore Ravens, another game on the road for the Bills.

CLICK HERE TO GET THE FOX NEWS APP

The Dolphins have a short week and aim to stay undefeated as they head to Cincinnati to face off against Joe Burrow and the Bengals on Thursday Night Football.