DENVER — At last, an entire city can exhale — and so can its football team.

The Denver Broncos defeated the San Diego Chargers in a divisional playoff game Sunday, building a 17-point lead then hanging on for a 24-17 victory in front of a bundled-up, boisterous crowd at Sports Authority Field.

The victory sets up an AFC showdown between New England and Denver — Tom Brady versus Peyton Manning — but on Manning’s home field this time.

“Obviously, we’re the two best teams in the AFC, because we’re playing for the AFC championship,” said Broncos linebacker Shaun Phillips, whose team blew a 24-point lead to the Patriots in a 34-31 loss Nov. 24 in Foxborough, Mass. “What more can you ask for as a football player?”

In winning, the top-seeded Broncos washed away some of the bitter taste from last season, when they let a divisional win against Baltimore slip through their grasp, lost in double overtime, and watched from home as the upstart Ravens went on to win the Super Bowl.

This time, the surging Chargers were the threat, and, after being shut out for three quarters, San Diego made a game of it with a rally in the fourth that included two touchdown passes from Philip Rivers to rookie Keenan Allen, a successful onside kick and a field goal.

Of San Diego’s slow start, Allen said: “I think we just came out flat and not how we wanted to. We couldn’t capitalize on third downs coming out of the first half. We tried to make a turnaround, but it was obviously too little, too late.”

Those scoring plays in the fourth quarter quieted the crowd, buffeted all game by a steady wind and temperatures in the 30s, but didn’t stifle Manning, who made the necessary big plays down the stretch to collect his first playoff victory since his Indianapolis Colts beat the New York Jets in the 2009 AFC Championship Game.

“I think the team needs to be commended for even getting to this point,” Manning said after beating the Chargers. “There’s a lot of teams that had disappointing losses last year — Atlanta, Washington — and everybody says in that locker room, ‘Hey, let’s get back next year.’ It just doesn’t happen. It’s hard to get back.”

Manning slammed the door on any thoughts of a San Diego comeback with a clutch drive that burned the final four minutes off the clock.

Manning converted two crucial third downs on that drive, both to tight end Julius Thomas — a sideline pass for 21 yards on third-and-17, and a 9-yard completion on third-and-six.

The third-and-17 will go down in Broncos lore as a magical Manning moment.

“Third-and-17, you know you’re going to have to hold the ball a little longer just to give guys a chance to get down the field,” Manning said. “It was the perfect call against the perfect coverage, which you may get one or two of those a game. It certainly came at a good time. Adam (Gase, offensive coordinator) dialed it up, it was something we worked on, and it was nice we were able to execute.”

In the first three quarters, the Chargers were dogged by all types of execution problems. They had five first downs to Denver’s 19; repeatedly were flagged for neutral-zone violations; and lost running back Ryan Mathews, who came into the game with a tender ankle and watched the second half from the sideline.

The Chargers, who ran for 177 yards against the Broncos in their December meeting, were held to 65. Denver, too, flipped that script, gaining 133 yards on the ground Sunday after being limited to 18 yards in the previous game against the Chargers.