That lead was soon extended by the visitors when Fred Jackson burst his way into the end zone with a three-yard run.
Miami finally got on the scoreboard in the second quarter when Tannehill threw a short pass to Charles Clay, who had an easy run to the end zone to complete a seven-yard score.
Carpenter kicked a 39-yard field goal for the Bills but Tannehill continued his recovery from the earlier pick six with his second touchdown pass of the night, this time finding Brandon Gibson, who leapt into the end zone.
Tannehill and Gibson combined again in the third quarter as the former took his time to pass the ball, eventually finding Gibson wide open in the end zone.
Carpenter reduced the deficit to just one point with a field goal early in the fourth quarter and another kick with just 36 seconds left on the clock secured the win for the Bills.