In perhaps the most important half of his career, Ryan Tannehill passed the test. He threw two second-half touchdowns to carry the Dolphins to a resounding 22-9 victory against the Buffalo Bills Thursday night.

The result not only broke a three-game losing streak to Buffalo. It also put separation between the Dolphins and the Bills — who posed a major threat to their playoff hopes.

Never miss a local story.

Sign up today for a free 30 day free trial of unlimited digital access.

With the win, Miami improved to 6-4 and, for now, moved into a three-way tie for seventh in the AFC. The Bills fell to 5-5, and far out of the Wild Card picture.

The Dolphins did all this despite losing the turnover battle (2-0). Despite failing on their first two red-zone drives. And despite allowing five sacks — including 3.5 by Mario Williams — behind a patchwork offensive line.

But when Tannehill had time to throw, he was pretty great — at least in the second half. On the night, he completed 26 of 34 passes for 240 yards, two touchdowns, no interceptions — and a passer rating of 114.8.

In doing so, he improved to 16-1 all-time when his rating was above 90. And he finally figured out how to beat the Bills.

“It was great. I never felt the monkey or anything like that,” Tannehill said. “It was a big game for all of us.”

The short version: Don’t be a sitting duck, and when Buffalo blitzes, throw to the hot route.

Oh, and have Lamar Miller run for 86 yards on 15 carries helps too.

Not to mention a lock-down second half by the defense, which limited the Bills to just 86 yards after the break. Granted, things weren't always so rosy.

The Dolphins entered the game with the league's third-worst red-zone offense — and showed why on their first drive.

After moving from their own 12 to the Buffalo 9, the Dolphins’ drive promptly stalled. The biggest reason: Shelley Smith committed a holding penalty on second-and-4. Miami couldn't recover and had to settle, as it has all-too-often, for a Caleb Sturgis field goal.

“It was definitely frustrating,” Tannehill said. “But I think the team — and offense, especially — felt confident in what we were doing.”

But one of two teams actually worse in the red zone than the Dolphins: the Bills, who reverted to form on their first drive. On third-and-4 from the 15, Kevin Coyle dialed up a blitz.

Koa Misi applied pressure, forcing Bills quarterback Kyle Orton into a quick throw, which Reshad Jones knocked down. Former Dolphin Dan Carpenter converted a 33-yarder and the game was tied at the end of a fast-moving first quarter.

Whatever the Bills could do, the Dolphins could do better — or worse, depending on your point of view. Miami again moved the ball with ease on its next drive, only to come up empty inside the 20. This time, the Dolphins didn't even get a field goal for their efforts.

Tannehill, trying to avoid the rush, was stripped from behind by Jerry Hughes. Duke Williams corralled the loose ball, and Tannehill lost his first fumble of the year.

That led to another Carpenter field goal, this time from 21 yards, and Buffalo went into the break with the lead.

In the first half, the Dolphins had 174 yards, 11 first downs — and just three points to show for it.

The self-inflicted wounds continued in the second half, when Jared Odrick lined up in the neutral zone on third-and-10. While the Bills still couldn't convert, it made the field goal attempt five yards easier for Carpenter, who pounded a 46-yarder to stretch the lead to 9-3.

The game began to get away from the Dolphins. And then Tannehill ripped it right back. He completed 5 of his next 6 passes for 59 yards, directing the game's first touchdown drive. On the scoring play, he play-action faked left and rolled right. Brandon Gibson, starting on the left side, flashed open in the middle of the field, and pulled in the touchdown.

Then, the game just got weird.

The Dolphins' defense, with a little help from the officials, added to its slim lead.

On third-and-long, Olivier Vernon planted Orton just as he was releasing the ball to seemingly no one. The refs ultimately decided to flag him for intentional grounding — giving Miami its second Thursday-night safety in as many years.

“It kind of set the tone for how we were playing defense in the second half,” coach Joe Philbin said.

On the ensuing free kick, weirdness again.

Jarvis Landry decided to catch and return a ball that was seemingly headed out of bounds. He paid the price for the mistake, fumbling the ball away. The Dolphins dodged a bullet, however. Carpenter missed from 47.

Six plays later, the Dolphins were in the end zone again. And Landry redeemed himself. Tannehill connected with the rookie, who made a cut a butcher would love, and dove eight yards into the end zone.

“It was a good win,” Philbin said. “We talked to the guys this morning and told them, ‘We have to step up. … You have to start playing good football this time of year.’”