FOXBOROUGH — Joe Flacco threw three touchdown passes in the second half as the Baltimore Ravens upset the New England Patriots 28-13 Sunday night in the AFC championship game at Gillette Stadium.

The Ravens will face the San Francisco 49ers in New Orleans in the Super Bowl on Feb. 3, setting up a match between brothers John Harbaugh and Jim Harbaugh, the head coaches of the Ravens and 49ers.

New England finished its season 13-5 – two of the losses to the Ravens. It was the first time the Patriots had ever lost an AFC championship game at home.

New England led 13-7 at the half, but missed an early opportunity to add to its score in the third quarter, then the Ravens took over.

Flacco completed an 87-yard drive with a 5-yard touchdown pass to Dennis Pitta with 6:14 left in the third quarter to make it 14-13.

Then, after the Patriots were forced to punt again, the Ravens drove 64 yards to get a 3-yard touchdown pass from Flacco to Anquan Boldin on the first play of the fourth quarter, making it 221-18.

Baltimore got the ball right back when defensive back Bernard Pollard crushed running back Stevan Ridley, forcing a fumble that was recovered by Baltimore’s Arthur Jones at the New England 47 – and knocked Ridley out of the game.

Four plays later, Flacco threw an 11-yard touchdown pass to Boldin and the crowd at Gillette started leaving with 11:13 remaining, the Patriots trailing 28-13.

Tom Brady completed 29 of 54 passes for 320 yards, a touchdown and two interceptions.