Playing at home and entering the contest on a three-game winning streak, the Lions struck first with a close-range Jamaal Williams touchdown in the first quarter.
The Bills would answer straight back with a 19-yard touchdown pass from Allen to Isaiah McKenzie on the next drive, and after trading touchdowns again in the second quarter, a Tyler Bass field goal as time expired gave Buffalo a 17-14 lead at half-time.
Defensive lineman Ed Oliver tacked on two more points for the Bills early in the third quarter when he sacked Lions quarterback Jared Goff in the endzone for a safety, but the hosts would not go away, taking the lead 22-19 to begin the fourth period after a D.J. Chark touchdown catch.
The see-sawing battle would see the Bills retake the ascendancy with under three minutes remaining through a five-yard Stefon Diggs touchdown reception, but the Lions looked destined to take it to overtime when Michael Badgley tied it up at 25-25 with a clutch 51-yard field goal, with only 23 seconds on the clock.
That proved to be enough time for Allen to win it, delivering a 36-yard strike to Diggs to move within field goal range, setting up Bass for another big kick, and another big make to take the Bills to 8-3.
Allen completed 24 of 42 passes for 253 yards, two touchdowns and one interception, while top receiver Diggs snagged eight receptions for 77 yards and a score.