FOXBOROUGH, Mass. — Booed off the field at the end of a first half in which Tom Brady threw for 25 yards, the New England Patriots responded with a command performance over the final two quarters to turn back the Miami Dolphins 27-17 Sunday at Gillette Stadium.

Keyed by the defense, New England scored 17 points in the third quarter, then put the game away in the fourth to beat the Dolphins.

The victory lifted New England to 6-2 and Miami dropped its fourth in a row to fall to 3-4.

Miami was driving early in the third quarter, leading 17-3, when Dont’a Hightower sacked quarterback Ryan Tannehill for a 9-yard loss. The Dolphins attempted a 46-yard field goal on the next play, but Caleb Sturgis hit the right goal post.

Brady, playing with a swollen right hand, then led the Patriots on a 64-yard drive, getting a 14-yard touchdown pass to Aaron Dobson. Stephen Gostkowski’s PAT made it 17-10.

The Patriots had the ball back two plays later as rookie Ryan Logan sacked Tannehill and forced a fumble, which was recovered by Rob Ninkovich at the Dolphins’ 13. Three plays later, Brandon Bolden ran in for a 2-yard touchdown. Gostkowski’s kick tied it at 17, with New England scoring two touchdowns in 1:46.

Gostkowski kicked a 48-yard field goal with 8 seconds left in the third quarter to give the Patriots the lead, 20-17.

Then the defense rose again five plays into the fourth. Tannehill threw deep down the right sideline to Mike Wallace. But safety Devin McCourty leaped and tipped the ball backward to teammate Marquice Cole, who tip-toed the sideline as he cradled the interception.

Brady then led New England on an 82-yard drive that was culminated by a 3-yard touchdown run by Stevan Ridley with 7:14 left that made it 27-17.

The defense had one more play in it. With Miami driving late, Ninkovich sacked Tannehill for a 6-yard loss, forcing the Dolphins to try a 39-yard field goal.

Chandler Jones blocked it.

Rookie Duron Harmon intercepted Tannehill on Miami’s final drive.

New England, which has lost two defensive starters for the season and was without cornerback Aqib Talib for the second consecutive game, suffered another injury. Right offensive tackle Sebastian Vollmer suffered an injury to his right leg with 7:16 left in the second quarter and had to be carted off the field. He was in extreme pain, slamming his fist into the ground after he was hurt.