But Flacco directed three consecutive scoring drives, moving the Ravens (9-7) in front 27-24 on a 6-yard touchdown pass to Mike Wallace with 8:48 left in the game.
The Bengals had just one first down and 17 yards in the second half before taking over at their own 10 with 2:43 to go. But Dalton (23 of 44 for 222 yards and three touchdowns) directed the game-winning drive and ran to the sideline to give Lewis a huge hug after Boyd’s touchdown.
In addition to knocking the Ravens out of the playoffs one week after eliminating the Detroit Lions, the Bengals victory put Buffalo into the postseason as the No. 6 seed, ending the longest playoff drought in all four of the major sports.
The game-winning drive was extended by a defensive holding penalty that negated a game-sealing interception by Baltimore safety Eric Weddle with 1:20 remaining.
Four plays later, Dalton hit Boyd for a touchdown that Bengals fans will remember for years to come.
Dalton hit Boyd at the 23, and the wide receiver got around Ravens cornerback Maurice Canady and out-ran cornerback Brandon Carr to the end zone.
Boyd finished with five catches for a career-high 91 yards.
Dalton threw a pair of touchdown passes to tight end Tyler Kroft in the first half and Randy Bullock kicked a 32-yard field goal with 23 seconds left before the break to put the Bengals up 17-3.
But Baltimore’s Chris Moore returned the ensuing kickoff 87 yards to the Cincinnati 6 with eight seconds to go, and Flacco went back to Moore for a touchdown pass on the next to play.
The only other points the Ravens had at that point were on a 46-yard field goal by Justin Tucker, which came three plays after Bengals running back Joe Mixon lost a fumble at the Cincinnati 34.
The Cincinnati defense held Baltimore to seven consecutive three-and-outs in the first half as the Bengals outgained the Ravens 268 to 61 through two quarters.
After Dennard’s pick six bumped the lead to 24-10 with 10:17 left in the third quarter, Flacco (25 of 47 for 203 yards with two touchdowns and an interception) direct scoring drives of 61, 62 and 45 yards.
Alex Collins’ 17-yard run on fourth and 3 got Baltimore within 24-17 with 6:16 left in the third, and a Tucker 34-yard field goal early in the fourth made it 24-20.
The Bengals followed with a three and out, and Flacco drove the Ravens for the go ahead score on the touchdown pass to Wallace.
There was another three andn out for the Cincinnati offense, but the defense held the Ravens on third and 7 to give Dalton and Co. one more crack at it. And they converted with an 11-play, 90-yard march to victory, capped by Boyd’s touchdown that sent Dalton charging to the sideline to embrace Lewis in a hug.