FOXBOROUGH, Mass. — You probably yelled at the television a little bit. Or a lot. If you were at Gillette Stadium, you certainly groaned and screamed. Your throat and stomach hurt.

After it was all over, after Joe Flacco’s final heave into the end zone was batted down, you appreciated what you witnessed – or least you should have if you’re a Patriots fan.

This was a heavyweight bout, neither the New England Patriots nor the Baltimore Ravens backing down.

In the end the Patriots hung on, beating the Ravens 35-31 in an AFC divisional-round playoff game Saturday as Tom Brady threw a late 23-yard touchdown pass to Brandon LaFell and second-year safety Duron Harmon intercepted Flacco in the end zone with less than two minutes remaining.

You can breathe now.

The Patriots are going to the AFC championship game for the fourth consecutive year, against either the Denver Broncos or Indianapolis Colts at Gillette next Sunday. There was no season-ending loss to the Ravens at Gillette this year, as in the 2009 and 2012 seasons.

No, just a tremendous effort by both teams, an example of how brilliant this game can be.

“It was everything we thought it was going to be, plus more,” said LaFell. “Both teams wanted to go out there and play physical, play fast and play smart, and that’s what happened.”

This was Brady vs. Joe Flacco, two of the best playoff quarterbacks in NFL history, both at their best. Flacco threw four touchdown passes, and Brady threw three and ran in for a score.

This was the Patriots pulling everything out of their offensive playbook, including a formation with just four offensive linemen that had the Ravens reeling, and a double pass in which Julian Edelman connected with Danny Amendola for a 51-yard touchdown that sent the crowd into a frenzy.

This was Amendola, much maligned in his two seasons with the Patriots, scoring two touchdowns to show that he still has something to offer.

This was the Patriots defense, built for a championship run, pushed around but again making big plays down the stretch.

This was the largest comeback in Patriots postseason history. New England twice rallied from 14 down to beat a team that backs down from no one.

It was all magnificent. It was great drama.

“I really think it comes down to character,” said Matthew Slater, the Patriots’ special teams ace. “A lot of times you focus on talent and ability and draft picks. But you can’t really put your finger on character. It’s guys who believe in one another are committed to one another. That goes a long way.”

It enables a team to overcome not just one but two 14-point deficits. The Patriots trailed 14-0 and then 28-14.

“Once you go down 14 for a second time, it’d be easy to throw in the towel,” said Slater. “But that’s not in our DNA, starting with our head coach and quarterback.”

The Ravens aren’t intimidated by anything the Patriots have done. Not the three Super Bowl titles. Not Brady. Not Rob Gronkowski. Not Darrelle Revis and Brandon Browner.

They bring a swagger into every stadium and Gillette is no different.

So maybe it shouldn’t have been surprising when Flacco threw two touchdown passes in the game’s first 10:16 – the second one to Steve Smith with Revis in coverage – to stake Baltimore to a 14-0 lead.

And maybe it shouldn’t have been surprising that the Ravens didn’t panic when the Patriots tied the game at 14, instead coming back to take a 28-14 lead when Flacco found Justin Forsett for a 16-yard walk-in touchdown in the third quarter.

But the Patriots aren’t seeded first because they collapse under pressure.

Brady threw a 5-yard touchdown pass to Gronkowski on a series that had the Ravens completely befuddled because the Patriots only had four offensive linemen on the field.

Then Julian Edelman, a quarterback at Kent State, took a backward pass from Brady and threw a 51-yard scoring strike to Amendola, who was 10 yards behind the nearest Raven, and the press box shook as the game was tied again, 28-28.

It was 31-28 when the Patriots got the ball back with just under 8:00 left.

That’s when Brady reached back for some of his playoff magic, driving the Patriots 71 yards in 10 plays for the go-ahead score, a 23-yarder to LaFell.

An unlikely hero emerged on defense in Harmon. With 1:46 left and facing second-and-5 from the Patriots 36, Flacco threw into the end zone to Torrey Smith. Harmon came over from the middle of the field to intercept the looping pass.

It was a great game to watch, though the players couldn’t appreciate it at the time.

Maybe later.

“I think you’re so focused on the next play, the next situation,” said Slater. “Are we aware of the next score? Yeah, but we’re just thinking about executing on the next play.

“I’m sure I’ll call my dad (NFL Hall of Famer Jackie Slater) and have a good talk about it.”

This was one that everyone will be talking about for a while.