ORCHARD PARK, N.Y. (WROC) — Up 17-0 early in the second quarter, it looked like the heavily-favored Bills would cruise to the next round of the playoffs.

The rest of the game was anything but a cakewalk, but the Bills were able to close out things after a shaky stretch and defeat the Dolphins 34-31.

The Bills took their early lead off of Dawson Knox and James Cook touchdowns in the first quarter. However, the Dolphins crawled back into the game after Allen threw two interceptions. The final setup a Mike Gesicki touchdown from Skylar Thompson, tying the game at 17.

The Bills got a field goal before halftime to go in front 20-17, but the Dolphins took their first lead of the game early in the third quarter. Allen was sacked and lost the ball, which was recovered by Zach Sieler who fell into the end zone for a touchdown and a 24-20 lead.

Allen finally got cooking once again, throwing two touchdowns to Cole Beasley and Gabe Davis as the Bills moved in front 34-24 and things seemed to be back to normal.

But the Dolphins marched back down the field on an 11-play, 75-yard drive which was capped off by Jeff Wilson, Jr. on a one-yard touchdown run to make it just a three-point game.

Miami had two chances with the ball to tie or retake the lead. The first was a three-and-out where they punted the ball away. The second sealed the game, as the Bills defense got a stop on fourth down to get the ball back. The Bills were able to run out the clock and escape with a victory.

The Bills will either host the Jacksonville Jaguars or the Cincinnati Bengals in the Divisional Round of the playoffs, depending on the result of Sunday night’s Bengals/Ravens game.