In winning for the ninth time in 10 games, the Dolphins (10-5) inched closer to their first playoff berth since 2008.
Miami can secure the AFC’s final wild-card berth as early as Sunday if Denver loses to Kansas City.
Denver needs to win its final two games to make the postseason and Baltimore is eliminated from the wild-card race and can only make the playoffs as the AFC North champion.
The Bills (7-8) were eliminated from contention and extended the NFL’s longest active playoff drought to 17 seasons.
Buffalo’s drought is tied for the fifth longest in NFL history, and the longest since the New Orleans Saints went 20 years before qualifying for the playoffs for the first time in franchise history in 1987.
Ajayi is the fourth player in NFL history to have at least three games with at least 200 rushing yards in a season. Earl Campbell, OJ Simpson, Tiki Barber are the others.
Franks forced overtime by hitting a career-best 55-yard field goal with 6 seconds remaining.
The Bills overcame a 14-point deficit three times before taking their first lead of the game with 1:20 left. That’s when Tyrod Taylor converted a fourth-and-7 by completing a pass to Charles Clay in the end zone.
The Bills squandered a scoring chance on the first possession of overtime when Dan Carpenter missed wide right from 45 yards with 10:03 remaining. Carpenter also missed wide right on a 46-yard attempt in the first quarter.
Two of Ajayi’s 200-yard games have come against Buffalo. He had a career-best 214 yards rushing and a score in the Dolphins’ 28-25 win over Buffalo at Miami on Oct. 23.
Though the Bills vowed to contain Ajayi, he broke loose on the first play from scrimmage on Miami’s second and final possession of overtime.
With Miami backed up at its 15, Ajayi took the handoff and stiff-armed defensive lineman Leger Douzable at the line of scrimmage in finding a crease off left tackle.
Matt Moore finished 16 of 30 for 233 yards and two touchdowns and an interception in making his second consecutive start in place of Ryan Tannehill, who is out with a sprained left knee.
DeVante Parker caught a 56-yard touchdown pass and Kenny Stills scored on a 6-yard catch.
Backup running back Kenyan Drake also scored on a 45-yard run .
The Bills’ defense squandered what was one of the team’s best offensive outings. Buffalo finished with 589 yards to beat the previous mark of 582 set against Miami on Sept. 1, 1991.
Taylor went 23 of 39 for a career-high 329 yards passing and three touchdowns. He became Buffalo’s first player to top 300 yards since journeyman Kyle Orton had 329 yards in a 26-24 loss at Oakland nearly two years ago to the day.
Sammy Watkins had 154 yards receiving and a touchdown.
LeSean McCoy had 128 yards rushing and also scored once.
The Dolphins appeared to be in control when Moore hit Stills for a touchdown to put Miami ahead 28-14 with 3:14 left in the third quarter.
The Bills responded by scoring 17 points on their next three possessions.
REPLAY CHALLENGE: Replays showed Bills coach Rex Ryan and safety Corey White attempting to call timeout as Franks lined up to kick his game-tying 55-yard attempt to force overtime. It appeared that Ryan was a split-second late in calling time. What’s unclear is if White’s motion was before the snap.
BAD PASS: Though the Dolphins had 126 yards rushing with two touchdowns in the first half, they inexplicably went to the passing attack.
The strategy backfired on each of Miami’s final two possessions of the half. Facing third-and-3 at the Miami 45, Moore made a poor throw to his right that tipped off Damien Williams’ fingers for an incompletion.
On the next drive, facing second-and-10 at the Buffalo 25, Moore attempted to hit Kenny Stills on a post-pattern in the end zone. Moore, however, sailed the pass, which was easily intercepted by White .
BAD TACKLING: Missed tackles led to Miami scoring its first three touchdowns in building a 21-7 lead 2:55 into the second half.
Ajayi opened the scoring by shedding defensive end Leger Douzable and then stiff-arming safety Sergio Brown.
Drake scored by finding no hole up the middle and then bouncing his way up the right side by beating linebacker Jerry Hughes to the edge.
And Parker’s 56-yard touchdown began with him making a short catch over the middle and having cornerback Nickell Robey-Coleman bounce off him.
Dolphins: Close regular season hosting New England Patriots on Jan. 1.
Bills: Close regular season at New York Jets on Jan. 1.