Updated

Ryan Tannehill ended his frustrating afternoon by heaving one final incompletion on the run, then took a tumble near the Buffalo Bills' bench and laid face down as they began to celebrate.

Too many Tannehill sacks and turnovers again doomed the Miami Dolphins, who fumbled away a late lead and lost Sunday to the Buffalo Bills, 23-21.

Mario Williams forced a fumble by sacking Tannehill with less than three minutes left, setting up the winning 31-yard field goal by Dan Carpenter.

Tannehill also threw two interceptions that made at least a 10-point difference. One ended a scoring threat, and rookie Nickell Robey returned the other interception 19 yards for a touchdown on the third play of the game to help the Bills build a 14-0 lead.

A month ago, the Dolphins (3-3) were basking in their best start since 2002. They haven't won since, and they'll take a three-game losing streak to New England on Oct. 27.

"We're in a tough spot right now," Tannehill said. "We have to face the adversity and grow from it. There are two ways we can go. We can tank it, or we can turn it around."

The injury-plagued Bills (3-4) ended a streak of six consecutive road losses, including two this year. They rallied after Brandon Gibson caught his second touchdown pass to put Miami ahead in the third quarter.

"It meant a lot to get this win," Bills quarterback Thad Lewis said. "Wins are hard to come by in this league. It's even sweeter to get it at home."

Lewis made his second consecutive start since being promoted from the practice squad to replace injured EJ Manuel. He was sacked four times and threw an interception, but helped the Bills convert 9 of 19 third downs.

The 99th meeting between the AFC East rivals had one of the wilder endings in the series. With Miami nursing a 21-20 lead, Tannehill tried to throw from midfield but fumbled when sacked by Williams. Kyle Williams recovered at the Miami 34, and former Dolphins kicker Carpenter made the winner seven plays later with 33 seconds left.

Marcus Thigpen nearly broke the ensuing kickoff for a touchdown, but was tripped up by Carpenter after a 44-yard return to the Miami 46. Tannehill then threw four consecutive incompletions, his final desperate toss landing in the end zone among a cluster of players as time ran out.

Tannehill, who came into the game on pace to set an NFL record for being sacked, increased his total to 26 with two — both by Mario Williams, who has 10 this year.

Each time Williams beat tackle Tyson Clabo.

"I have to take full responsibility," Clabo said. "He's a really good player. He made a big play at a crucial point in the game. That's why he's considered one of the best defensive ends in the league."

Tannehill almost offset his mistakes with three touchdown passes. Gibson turned one short throw into an acrobatic score, leaping over one defender at the goal line and splitting two others as he tumbled airborne into the end zone.

His spinning limbs made him look like a helicopter, and the 13-yard score with 21 seconds left in the first half cut Buffalo's lead to 17-14.

"I looked up and saw it on the scoreboard as I was on the ground," Tannehill said. "It was pretty fun to watch."

Gibson made his second TD catch just as entertaining. After catching a 4-yard pass in the back of the end zone, he flipped the ball aside, leaped over a barricade and was mobbed by more than a dozen happy fans watching from field level.

Coming off a bye, the Dolphins looked lethargic at the start. Robey jumped a short route to intercept Tannehill and somersaulted across the goal line for a 7-0 Bills lead.

Tannehill cost the Dolphins again when his ill-advised lob was intercepted at the goal line by Aaron Williams. He finished 19 for 37 for 194 yards.

"He had some ups, he had some downs, just like everyone else," teammate Mike Wallace said. "We've got to pick it up. We can't win games like this."

Miami rookie Don Jones was penalized when he came from out of bounds to down a punt at the 15, and the mistake cost Miami 40 yards when they were forced to re-kick. Buffalo took advantage of the break in field position to score six plays later for a 14-0 lead.

"I have to do a better job of getting the team ready to play," coach Joe Philbin said. "We did not come out playing very well."

The Dolphins' Caleb Sturgis missed a 51-yard field goal in the first half when his kick hit the right upright, which ultimately made the difference in the game.

Notes: Bills LB Manny Lawson left the game in the third quarter with a hamstring injury. ... Dolphins DE Cameron Wake saw sporadic action after missing most of the past three games with a left knee injury. ... Miami CB Dimitri Patterson had a sack in his first game since suffering a groin injury in the season opener. ... The Bills have still scored at least 20 points in every game.

___

AP NFL website: www.pro32.ap.org and http://twitter.com/AP_NFL

___

Follow Steven Wine on Twitter: http://twitter.com/Steve_Wine