Safety Jairus Byrd forced a fumble and had an interception, while Bryan Scott sealed the victory with his second interception to end the Dolphins’ last-gasp drive in the final minute. Williams had one of three sacks for a Buffalo defense that limited the Dolphins to 184 yards and 16.

That more than made up for an offense that lacked finish. Rian Lindell hit four field goals, including a 42-yarder, as Buffalo failed to score an offensive touchdown despite four trips inside the Dolphins 20.

Leodis McKelvin opened the scoring 90 seconds in by returning a punt 79 yards for a touchdown in a game the Bills never trailed.

The Bills (4-6) snapped a three-game skid and won for only the second time in seven games to stay on the fringes of the AFC playoff hunt. Buffalo also ended several other inglorious skids, by beating a division rival for the first time in nine meetings, and snapping an 11-game prime-time drought that dated to 2001.

Marcus Thigpen scored on a 96-yard kickoff return and Davone Bess had a 2-yard touchdown catch for Miami (4-6), which has lost three straight.

Rookie quarterback Ryan Tannehill continued to struggle for Miami. He finished going 14 of 28 for 141 yards with a touchdown and two interceptions. He was coming off a dreadful outing in which he threw three interceptions in a 37-3 loss to Tennessee last week. The No. 8 pick out of Texas A&M has thrown six TD passes and 11 interceptions.

It wasn’t all Tannehill’s fault as the usually sturdy Dolphins defense gave up 120 yards rushing, including 91 to C.J. Spiller, who took over the bulk of the rushing duties in place of Fred Jackson (concussion).

After allowing 307 yards rushing in its first five games, Miami’s now given up 661 in its past five.

For Buffalo, it was a long-awaited breakout performance for a high-priced defense that entered the game among the NFL’s worst. Buffalo had ranked 31st in yards allowed and last in allowing an average 31.67 points per game.

Williams was supposed to be the defense’s centerpiece after signing a six-year, $100 million contract March. He’s finally starting to play up to the deal, and his sack gave him a team-leading 5 1/2.

The unit forced three turnovers after failing to produce one its past three games.

Buffalo didn’t allow the Dolphins to cross midfield until their eighth drive, 11 minutes into the third quarter. And that drive ended with Dan Carpenter missing a 50-yard field-goal attempt in which the ball glanced off the outside of the right goal post.

The Dolphins did provide the Bills a scare midway through the fourth quarter. Tannehill capped an 11-play, 81-yard scoring drive by hitting Bess in the end zone with 8:42 remaining. The next two possessions ended with Tannehill throwing interceptions.

Thigpen’s kickoff return cut the Bills lead to 10-7 with 4:55 left in what proved to be a wild first quarter that began with McKelvin’s touchdown.

The last time there was a punt return touchdown by one team and a kickoff return touchdown by the opposing team in the same quarter was December 1999 in a game between the Washington Redskins and Detroit Lions according to STATS LLC. Washington’s James Thrash had a 95-yard kickoff return for a score and Detroit’s Desmond Howard had a 68-yard punt return for a touchdown in the second quarter.