FOXBOROUGH, Mass. (AP) It wasn’t last season’s “Miami Miracle” loss. But the Patriots' latest setback could wind up affecting their prospects of repeating as Super Bowl champions.

The Dolphins dropped New England into the wild-card playoff round when Ryan Fitzpatrick tossed a 5-yard touchdown pass to tight end Mike Gesicki with 24 seconds remaining for a stunning 27-24 victory Sunday.

New England (12-4) will have to play in the opening weekend of the postseason for the first time since 2009. The Patriots never have made the Super Bowl while playing in the wild-card round.

They will face Tennessee (9-7), which earned the final AFC wild card with a win at Houston.

“We didn’t play the way we were capable of playing and it ended up costing us," quarterback Tom Brady said. "Just too many bad mistakes.”

The Dolphins (5-11) scored on a wild series of laterals on the final play to win the second meeting between the teams last season, in Miami.

This time, it was Fitzpatrick’s turn to provide all the magic heavy underdog Miami needed to end its AFC rival's streak of nine straight first-round playoff byes.

After trailing throughout the game, Brady threw a 13-yard touchdown pass to James White to put New England in front 24-20 with 3:53 left. But Fitzpatrick, who finished 28 of 41 for 320 yards and a touchdown, was unflappable, leading Miami on a 13-play, 75-yard drive that included him recovering a fumbled snap, and completing a 24-yard pass to DeVante Parker.

“I know how difficult it is to beat them,” Fitzpatrick said. “I know how difficult it really is to beat them at home. I’m proud of what we did out there today.”

It also gave first-year Dolphins coach Brian Flores, who spent 15 seasons as New England assistant, a season split with former boss Bill Belichick. Miami finished the season 5-4 after an 0-7 start.

“It took all 60 minutes,” Flores said. “I'm proud of that group.”

For New England, it's a head-scratching conclusion to a regular season that has been replete with inconsistency.

The Patriots won their first eight games, then split the next eight, including the rarity of two losses at home.

New England's defense, which entered the week ranked No. 1 in the NFL, allowed the Dolphins to rack up 389 yards and go 5 of 12 on third down. The Patriots were allowing teams a league-low 23% on third down entering the day.

“Nobody feels sorry for the Patriots not getting a first-round bye in the playoffs," safety Devin McCourty said. "We gotta move forward and get ready to go or the end of our season will be next week if we don't turn the page and play good football way better than today.”

This is also the second straight season the Dolphins have denied the Patriots an unbeaten division record. Despite winning 11 straight AFC East titles, New England has only finished 6-0 in division play twice - in 2007 and 2012.

Miami (5-11) made New England play catch-up for most of the game and led 10-0 early and 20-17 in the fourth quarter.

Brady finished 16 of 29 for 221 yards with two touchdowns and an interception. He went over 4,000 yards for the 11th time in his career, tying him with Philip Rivers for fourth on the all-time list.

The Dolphins drove inside the Patriots 20 early in the fourth quarter, but settled for a 32-yard field goal by Jason Sanders to take a 20-17 lead with 8:29 remaining.

Brandon Bolden gave the Patriots good field position, taking the ensuing kickoff and returning it 38 yards to the New England 40. Rex Burkhead rushed 14 yards on the first play to get the Patriots across the 50.

Brady completed a short pass to Ben Watson, followed by a 20-yard strike to Mohamed Sanu. Three plays later, Brady connected with White for the go-ahead score.

But it wasn't enough.

The Dolphins made it clear from the outset that they weren't going to allow the Patriots to coast. Miami took a 10-0 lead in the second quarter when Eric Rowe stepped in front of Brady's pass to Julian Edelman and returned it 35 yards for a touchdown. It was Brady's first career pick-6 against the Dolphins.

It also marked the first time the Dolphins led the Patriots by double digits since Week 8 of the 2013 season. New England won that game 27-17.

Miami twice saw its leads evaporate on Sunday as well.

The Patriots got a 25-yard field goal from Nick Folk. They tied it by capping a five-play, 82-yard drive with a 4-yard run by Sony Michel just before the half. Michel's TD was set up by a 50-yard pass from Brady to Phillip Dorsett along the sideline, his first catch since Week 13.

Later, trailing 17-10 in the third, the Patriots went deep in the playbook when Brady connected with linebacker and part-time fullback Elandon Roberts for a 38-yard touchdown.

NOTHING TO LOSE

With no postseason to look forward to, Miami pulled out plenty of trickery.

Facing a fourth-and-3 on the Patriots 45 on the opening drive, the Dolphins attempted a fake punt. But holder Matt Haack's pass to Deon Lacey was high and landed far out of bounds.

The tricks continued when receiver Isaiah Ford scrambled for a first down after an aborted pass attempt. The Dolphins drove to the Patriots 9 before the 12-play, 80-yard drive ended with a 27-yard field goal by Sanders that put Miami in front 3-0.

Miami used even more misdirection in the third quarter when receiver Albert Wilson tossed a 20-yard pass to running back Patrick Laird. Four plays later, Fitzpatrick ran it in from 2 yards to put Miami in front 17-10.

IRON MAN

Sunday’s start also marked Brady’s 16th season starting 16 games, tying Peyton Manning for second all time. Brett Favre holds the NFL record at 17 seasons of 16 starts.

INJURIES

Dolphins: Safety Walt Aikens left in the fourth quarter with an ankle issue.

UP NEXT

Dolphins: End of season.

Patriots: Will play on the opening weekend of the postseason for the first time since 2009.

---

More AP NFL: https://apnews.com/NFL and https://twitter.com/AP-NFL

Copyright 2019 by STATS LLC and Associated Press. Any commercial use or distribution without the express written consent of STATS LLC and Associated Press is strictly prohibited.