MIAMI GARDENS, Fla. — The Buffalo Bills snapped the longest current non-playoff drought in North American pro sports with a 22-16 victory Sunday over the Miami Dolphins, making the postseason for the first time since 1999.

The Bills got the help they needed when Cincinnati rallied past Baltimore, allowing Buffalo to grab the final wild-card berth in the AFC.

The Bills watched the dramatic finish of the Bengals game in the locker room, then celebrated.

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

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

The Bills’ joy was tempered by the loss of 1,000-yard rusher LeSean McCoy because of a right ankle injury. He was carted off the field in the third quarter and was in a walking boot after the game.

BENGALS 31, RAVENS 27: Baltimore (9-7) was ousted from the playoff hunt in stunning fashion by visiting Cincinnati (7-9) when Andy Dalton threw a 49-yard touchdown pass to Tyler Boyd with 44 seconds left.

Baltimore rallied from a 14-point deficit to take its first lead with 8:48 remaining. But Dalton put together a 90-yard drive in the closing minutes and hit Boyd over the middle on a fourth-and-12 play.

STEELERS 28, BROWNS 24: Cleveland joined the 2008 Detroit Lions as the only teams in NFL history to go 0-16 when it failed to find a way to win at Pittsburgh (13-3), which rested many of its top players.

TITANS 15, JAGUARS 10: Marcus Mariota threw a touchdown pass and used his legs to help Tennessee (9-7) end an eight-season playoff drought by beating visiting Jacksonville (10-6).

FALCONS 22, PANTHERS 10: Matt Bryant kicked five field goals, including a 56-yarder, for all of Atlanta’s second-half points and the Falcons (10-6) clinched a playoff spot by beating visiting Carolina (11-5).

BUCCANEERS 31, SAINTS 24: Jameis Winston passed for 363 yards, including a 39-yard scoring pass to Chris Godwin with nine seconds remaining, to help Tampa Bay (5-11) snap a five-game losing streak with a victory at home against playoff-bound New Orleans (11-5), which won the NFC South because of Carolina’s loss in Atlanta.

VIKINGS 23, BEARS 10: Minnesota’s defense turned in another dominant performance and Latavius Murray rushed for 111 yards and two touchdowns, helping the Vikings (13-3) win at home and secure a first-round bye for the playoffs.

CHIEFS 27, BRONCOS 24: Patrick Mahomes II made his first start a success, leading Kansas City (10-6) to a win at Denver (5-11) on Harrison Butker’s 30-yard field goal as time expired.

COWBOYS 6, EAGLES 0: Dak Prescott tossed a 20-yard touchdown pass to Brice Butler in the fourth quarter and Dallas (9-7) beat playoff-bound Philadelphia (13-3), which rested several starters after securing the NFC’s No. 1 seed last week.

LIONS 35, PACKERS 11: Matthew Stafford threw three TD passes and Detroit (9-7) beat visiting Green Bay (7-9).

COLTS 22, TEXANS 13: Jacoby Brissett threw for one touchdown and Marlon Mack ran for another as Indianapolis (4-12) defeated visiting Houston (4-12).

GIANTS 18, WASHINGTON 10: Eli Manning threw a TD pass in what might be his final game with the Giants (3-13), who beat visiting Washington (7-9).

CARDINALS 26, SEAHAWKS 24: Phil Dawson kicked four field goals, the last from 42 yards with 2:21 left, and Blair Walsh missed a 48-yard attempt with 32 seconds as Arizona (8-8) won at Seattle (9-7).

49ERS 34, RAMS 13: Jimmy Garoppolo threw for 292 yards and two touchdowns to lead visiting San Francisco (6-10) to its fifth straight win while the Rams (11-5) rested several stars.

CHARGERS 30, RAIDERS 10: Philip Rivers passed for 387 yards and three touchdowns, but Los Angeles (9-7) missed out on a playoff berth despite its win at home against Oakland (6-10).