Tom Brady threw for 406 yards and three touchdowns, and the New England Patriots beat the Baltimore Ravens, 30-23, in Foxboro, Mass. on Monday night.

Ahead 16-3 at halftime and up by 20 points early in the third quarter, New England (11-2) seemed to have the game won when Baltimore (7-6) rallied for two touchdowns in under a minute-and-a-half. The Ravens capitalized on two fumbles by New England’s special teams to close within 23-20 early in the fourth quarter.

Brady then saved the Pats, tossing a 79-yard TD pass to Chris Hogan to give his team all the points they would need. Hogan finished with five catches for 129 yards and the key score.

Joe Flacco was 37 of 52 for 324 yards with two touchdowns and an interception for Baltimore. The Ravens fell a game behind the Steelers in the AFC North race as a result of the loss.