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.

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. Ryan Tannehill capped an 11-play, 81-yard scoring drive by hitting Bess in the end zone with 8:42 remaining.

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.