Buffalo (9-7) will travel to face Jacksonville next Sunday. The Jaguars are coached by Doug Marrone, who resigned as the Bills’ coach three years ago.
The Bills’ joy was tempered by the loss of the 1,000-yard rusher LeSean McCoy with a right ankle injury. He was carted off the field in the third quarter and was in a walking boot after the game.
“Hopefully it’s not as bad as it seemed,” quarterback Tyrod Taylor said.
The frustration of a disappointing season got the best of the Dolphins (6-10) with 6 minutes 21 seconds left, when receiver Jarvis Landry, running back Kenyan Drake and offensive lineman Jake Brendel were ejected after a fight. Landry was cited for disrespecting an official, and Drake for throwing his helmet 20 yards in anger. Unsportsmanlike-conduct penalties were called against both teams.
The fight followed a 1-yard touchdown reception by Landry. On the play before that, a 98-yard fumble return for a touchdown by the Bills’ Preston Brown was negated by a replay review, and the Dolphins kept possession.
The undisciplined Dolphins, who came into the game with the second-most penalties in the N.F.L., had 14 penalties for 145 yards.
For the Bills, however, nearly two decades of frustration ended.
“The locker room is electric, man,” said guard Richie Incognito, who finished a season above .500 for the first time in his 11-year career. “We have been working so hard for this. So much has been said about it. And now the monkey is off our back. We’re in the postseason, and we’ve got new life.”
Buffalo punctuated the memorable victory with a 1-yard touchdown run by Williams for the first score of his career.
“I thought, ‘Try not to screw it up,’” he said. “‘They’re not going to call it again if I screw it up.’”
He and his teammates celebrated with choreographed back flops in the end zone.
The golf great Jack Nicklaus smiled from the stands as his grandson, tight end Nick O’Leary, caught Taylor’s 26-yard touchdown pass.
The Dolphins scored a touchdown with 1:56 left and recovered the ensuing onside kick, but Jordan Poyer’s interception sealed the win.
Taylor went 19 for 27 for 204 yards and one score. In six games against Miami, he has 10 touchdown passes and no interceptions.
For the Dolphins, the season finale had the feel of an exhibition game, with thousands of empty seats and David Fales giving a lengthy, unimpressive audition as a potential backup quarterback in 2018. Miami was eliminated a week ago and will sit out the playoffs for the eighth time in the past nine years.
“I guess it’s a little perplexing,” defensive end Cameron Wake said.
Miami’s starting quarterback, Jay Cutler, took three snaps before he was replaced by Fales, a sixth-round draft pick by Chicago in 2014. Fales, who came into the game with only two career completions, went 29 of 42 for 265 yards with one score and one interception.
Cutler, 34, who ended a brief retirement to join the Dolphins this season, has said he has not decided whether he wants to play in 2018. Ryan Tannehill is expected to start next season in a comeback from knee surgery.
Miami lost to Buffalo for the seventh time in their past 10 meetings.