Updated

Miami, FL (SportsNetwork.com) - Michael Thomas twice thwarted the New England Patriots' bid for a fourth consecutive come-from-behind win.

The Miami safety broke up a would-be touchdown catch before picking off New England quarterback Tom Brady in the end zone with two seconds remaining to seal a 24-20 win at Sun Life Stadium that currently puts the Dolphins in possession of the final playoff spot in the AFC.

Ryan Tannehill threw three touchdown passes for Miami (8-6), the last erasing a 20-17 deficit with 1:15 left in the fourth quarter. Tannehill finished with 312 yards on 25-of-37 efficiency in the Dolphins' third straight win. They moved a half-game ahead of Baltimore in the battle for the sixth seed. The Ravens visit Detroit on Monday night.

"I liked the way the guys contributed in all three phases, made plays in order to get the outcome that we got. It wasn't one player or one unit," said Miami coach Joe Philbin.

Brady completed 34-of-55 passes for 364 yards and two touchdowns, but the Patriots (10-4) squandered an opportunity to clinch their fifth straight AFC East title. New England can still secure a playoff spot with a Ravens loss.

The Patriots also missed out on a chance to seize control of the conference's top seed.

Miami, which still has a shot at the AFC East crown, totaled 17 points on three consecutive possessions after New England had built a 10-0 lead late in the second quarter, with a 2-yard TD grab by Daniel Thomas to begin the fourth quarter giving the Dolphins the lead.

The next Patriots drive comprised of 15 plays, but stalled at the Miami 5. Stephen Gostkowski kicked a 23-yard field goal to close the gap to 17-13 with 7:45 to play.

After Miami went three-and-out, the Brady-led New England offense covered 73 yards in six plays and Julian Edelman's 24-yard TD catch put the visitors back on top with 4:07 remaining. Edelman made the grab as he came across the middle and he zig-zagged his way to the end zone.

Gostkowski then made a critical error, booting the kickoff out of bounds.

The Dolphins started at their own 40-yard line and Charles Clay made a big play on fourth down to keep the drive alive. The tight end's lone reception of six yards moved the chains on 4th-and-5 from the Miami 45.

A few plays later, Tannehill hit Rishard Matthews along the left sideline for a 24-yard gain to the New England 14. The Miami quarterback then connected with Marcus Thigpen for the go-ahead score.

Brady nearly orchestrated another rally. He did find Danny Amendola for 12 yards on 4th-and-8 from the New England 33. Amendola managed to make the catch despite absorbing a jarring hit.

The wide receiver, however, was not able to hold onto a potential game-winning touchdown grab later in the drive as Michael Thomas broke up the pass before hauling in Brady's intended throw to Austin Collie.

New England had tied an NFL record with three straight wins in which it trailed by at least 10 points in the second half.

"We had plenty of chances all day," Brady said. "We make some good plays and then we make plenty of (expletive) plays."

The Patriots methodically marched down the field on their first possession with a mix of LeGarrette Blount runs (25 yards) and completions mostly to Edelman (three for 34 yards). They converted a trio of 3rd-and-shorts and chewed up seven-plus minutes of the clock on the 16-play sequence.

New England, however, had to settle for a Gostkowski 22-yard field goal after Josh Boyce dropped a third-down pass in the end zone.

The Dolphins looked to get on the board late in the second quarter, lining up for a field-goal attempt, but they botched the kick. The ball was snapped directly into the face of the holder Brandon Fields, who was totally unprepared on the play.

The ensuing New England drive began with a 30-yard catch-and-run by Amendola and ended with Michael Hoomanawanui's one-handed grab for a 13-yard touchdown with 1:38 remaining in the second.

Miami was able to counter before halftime as Tannehill zipped a pass to Mike Wallace, who got inside position on Marquice Cole and sprinted 39 yards to the end zone.

With an opportunity to stretch the lead, Gostkowski missed a 48-yard try wide left to open the second half.

There was no mishap involving the snap a second time as Caleb Sturgis nailed a 32-yard field goal on the next drive to knot the score at 10-all with 7:31 left in the third quarter.

Game Notes

The Dolphins snapped a seven-game losing streak to New England ... Tannehill (3,627) joined Dan Marino and Chad Pennington as the only QBs in Dolphins history to reach 3,500 yards passing in a season ... Brady surpassed John Elway (4,123) for fifth place on the NFL's all-time completions list with 4,150 ... Gostkowski has now made 23 straight fourth-quarter field goals ... The Patriots had not allowed any fourth-quarter points in their previous five games against AFC East opponents ... Wallace caught six passes for 105 yards ... Edelman made 13 grabs for 139 yards, while Amendola finished with 131 yards on 10 receptions ... Patriots offensive tackle Nate Solder left the game with a head injury and did not return.