MIAMI -- Former Miami Dolphins kicker Dan Carpenter made a 31-yard field goal with 33 seconds left and quarterback Thad Lewis, a Miami native, won his first NFL game as the Buffalo Bills defeated the Dolphins 23-21 Sunday afternoon at Sun Life Stadium.
Carpenter, who made three field goals, also made a key tackle on the ensuing kickoff return by Marcus Thigpen, breaking up a possible touchdown.
The winning field goal was set up by Mario Williams' strip sack of Ryan Tannehill, which was recovered at the Miami 34 by Kyle Williams. An 8-yard third-down run by Fred Jackson was also key.
Buffalo (3-4), which snapped a two-game losing streak, will play at the New Orleans Saints next Sunday.
The Dolphins (3-3), which has lost three games in a row, will play at the AFC East-leading New England Patriots next Sunday.
Lewis, playing because of the injury to starter E.J. Manuel, is now 1-2 as an NFL starter.
Miami took a 21-17 third-quarter lead on a 4-yard Tannehill pass to Brandon Gibson, their second TD connection of the day. Tannehill capped the 11-play, 66-yard drive by scrambling to his right before finding Gibson in the right corner of the end zone.
Buffalo closed to within 21-20 with 14:16 left in the fourth quarter on a 20-yard field goal by Carpenter.
The Bills opened the first-quarter scoring when backup defensive back Nickell Robey jumped a Gibson out route, intercepting Tannehill's first pass of the game and returning it 19 yards for a touchdown.
Jackson, who left the game on his team's first possession after suffering a knee injury, returned on the next drive to score a 3-yard touchdown. That capped a six-play, 44-yard march after the Bills pinned Miami deep in its own territory.
The Dolphins ended the first quarter trailing 14-0 after Tannehill was picked off again, this time in the red zone. He tried to lob the ball to Brian Hartline but was instead intercepted by safety Aaron Williams at the goal line.
With 10:59 left in the first half, the Dolphins got on the board with a 7-yard pass from Tannehill to tight end Charles Clay to make it 14-7.
The Dolphins got the ball right back at the Buffalo 31 after safety Chris Clemons intercepted Lewis on a pass over the middle intended for Stevie Johnson.
But Miami could not move the ball, and Caleb Sturgis' 51-yard field goal attempt was wide right.
Buffalo extended its lead to 17-7 with a 39-yard field goal by Carpenter.
The Dolphins closed the first-half scoring with a 13-yard touchdown pass to Gibson with 21 seconds left. Gibson took a hit and vaulted about 5 yards to complete the play, capping a 75-yard drive that took just 1:04 and closed Miami's deficit to 17-14.
Notes: Johnson returned to the starting lineup after missing one game due to a back injury. ... Robey is a native Floridian (Frostproof). ... Bills LB Manny Lawson left the game in the third quarter due to a hamstring injury. ... Dolphins DE Cameron Wake, who missed all but three plays of the past two games due to a knee injury, returned to the starting lineup. ... The Dolphins started Jason Trusnick at MLB in place of leading tackler Dannell Ellerbe (shoulder injury). It was just the eighth start in the past four years for Trusnick, 29. ... The Dolphins activated DT Isaako Aaitui from the practice squad. He was undrafted out of UNLV two years ago.