MIAMI GARDENS, Fla. (AP) Amid the dancing and screaming and hugs and high-fives in the Buffalo Bills' locker room , defensive tackle Kyle Williams watched his two young sons climbing around in his stall.

''What do you think, boys?'' Williams shouted. ''Where are we going? The playoffs?! Yeah!!''

His sons are only 6 and 4. For their dad and most Buffalo fans, Sunday was a long time coming.

The Bills snapped the longest current non-playoff drought in North American pro sports, making the postseason for the first time since 1999. They avoided elimination by beating Miami 22-16, and clinched an AFC wild-card berth minutes later when Cincinnati rallied past Baltimore.

The Bills watched the dramatic finish of the Bengals game on locker room TVs, and then erupted.

''Everybody went crazy,'' said Williams, who is in his 12th and perhaps final season with the Bills. ''I've been a wreck for 10 to 15 minutes.''

His voice choked with emotion, and he wasn't the only one.

''Well I started crying, if that's a good reaction ...'' former Bills running back Thurman Thomas said in a text to The Associated Press.

Buffalo (9-7) will travel to face Jacksonville and former Bills coach Doug Marrone on Sunday. Marrone resigned as Bills coach three years ago Sunday.

The Bills' joy was tempered by the loss of 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 and tears 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:21 left, when receiver Jarvis Landry, running back Kenyan Drake and offensive lineman Jake Brendel were ejected following 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 undisciplined Dolphins, who came into the game with the second-most penalties in the NFL, had 14 for 145 yards.

Meanwhile, for the Bills, 17 seasons 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. They're not going to call it again if I screw it up,''' he said.

He and his teammates celebrated with choreographed back flops in the end zone.

''I was a little surprised at the touchdown celebration,'' Taylor said. ''I was the only one who wasn't aware of falling down.''

Golf great Jack Nicklaus wore Bills gear and a smile watching 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.

REVERSAL

A 98-yard fumble return for a touchdown by the Bills' Preston Brown was negated by a replay review. Instead, the Dolphins kept possession, and Landry scored on a 1-yard reception on the next play, when the fight broke out.

MIAMI QBS

Miami starter Jay Cutler took three snaps before he was replaced by Fales, a sixth-round draft pick by the Bears in 2014. Fales, who came into the game with only two career completions, went 29 for 42 for 265 yards with one score and one interception.

''Jay was great as far as saying, `Just let him go. Let him play a full game,''' coach Adam Gase said.

INJURY REPORT

Bills: McCoy was hurt when he carried up the middle. After being tackled, he pounded the turf with his fist as trainers attended to him. He had 10 yards on 11 carries to finish with 1,138 yards rushing, and added 448 receiving on a team-high 59 catches. ... RT Jordan Mills (ankle) was helped off the field late in the second quarter.

Dolphins: LB Kiko Alonso suffered a neck injury.

UP NEXT: Buffalo will play a postseason game for the first time since losing at Tennessee in the Music City Miracle game in January 2000.

''Obviously the Bills have achieved something they haven't done in a while,'' Bills owner Terry Pegula said. ''If we get a win next week, that's what it's all about.''

---

AP Sports Writer John Wawrow in Orchard Park, New York contributed to this report.

---

More AP NFL: http://pro32.ap.org and https://twitter.com/AP-NFL

---

Follow Steven Wine on Twitter: http://twitter.com/Steve-Wine .

Copyright 2017 by AP. Any commercial use or distribution without the express written consent of AP is strictly prohibited.