The sudden vulnerability of the Kansas City Chiefs was on vivid display for much of Sunday afternoon. They seemed on their way to losing at home to the Baltimore Ravens and, with the New England Patriots on the verge of securing a rare-for-them victory in Miami, the No. 1 seed for the AFC playoffs appeared to be slipping from the Chiefs’ grasp.

Then the greatness of Patrick Mahomes intervened. And that, combined with the miraculous ending of the Patriots-Dolphins game, has the Chiefs looking very good to be the AFC’s top postseason seed.

“I’m saying the road to the Super Bowl is going through Kansas City,” former Dallas Cowboys quarterback Tony Romo said on the CBS broadcast.

It was a dramatic late-afternoon turn of events. The Chiefs converted a pair of fourth downs on their way to a game-tying touchdown, shook off a missed field goal at the end of regulation and beat the Ravens, 27-24, in overtime. That clinched a playoff spot for the Chiefs and, with the losses by the Patriots and Houston Texans, strengthened their grip on the No. 1 seed.

“Everybody was stepping up and staying alive,” Mahomes told CBS of a game in which Chiefs wide receiver Tyreek Hill and running back Spencer Ware spent time on the sideline with injuries.

But, mostly, this was about Mahomes, the marvelous second-year quarterback who is prominent in the league MVP conversation. He threw for 377 yards and two touchdowns on 35-for-53 passing against the NFL’s top-ranked defense. Ravens defenders harassed Mahomes all day, recording an interception and three sacks.

“They’re good,” Mahomes said. “They’re really, really good.”

But Mahomes kept creating something out of nothing. He kept improvising and moving around and making throws from all arm angles and with all manner of creativity. He completed sidearm passes. He connected on a no-look throw. And he was at his very best in crunchtime.

In the final two minutes of regulation, the Chiefs were facing a 24-17 deficit and were in a fourth-and-nine predicament from their own 40-yard line. Mahomes was chased from the pocket and, as he ran to his right, lofted a pass down the middle of the field. Hill dashed in and made the catch, zipping to the Baltimore 12-yard line for a 48-yard gain. That led to Mahomes’s fourth-and-three touchdown pass to running back Damien Williams in the final minute of regulation.

Chiefs Coach Andy Reid called it the best game that Mahomes has played this season.

“This defense was a huge, huge challenge,” Reid said at his postgame news conference.

The Chiefs had their chance to win before overtime when Justin Houston stripped the ball from Ravens rookie quarterback Lamar Jackson on a sack. But Chiefs kicker Harrison Butker pushed a 43-yard field goal try wide right at the end of regulation. No matter. The Chiefs got a 35-yard field goal by Butker in overtime, then managed a defensive stop on a fourth-down incompletion thrown by Robert Griffin III — who took over at quarterback after Jackson was knocked from the game a couple of plays earlier — that left the Ravens looking for a pass interference call they wouldn’t get.

This was far from easy for the Chiefs. Hill left the game with what appeared to be separate injuries to his hand or wrist and, later, to his ankle or foot. But he kept coming back. Ware reentered the game after falling hard on his shoulder while being tackled along the sideline. He’s filling in at running back for Kareem Hunt, who was the league’s fifth-leading rusher when he was cut by the Chiefs after TMZ released video showing Hunt shoving and kicking a woman in a February incident at a Cleveland hotel.

The on-field implications of the Hunt move are that the Chiefs no longer are as dominant on offense as they were earlier this season. They won in Oakland in the first game after Hunt’s release. They beat the Ravens on Sunday. But Sunday’s win took all the magic that Mahomes could summon.

Now the Chiefs, with a record of 11-2, can secure the AFC’s top seed by winning two of their remaining three regular season games. But even that is not automatic. They have a quick turnaround before hosting the Los Angeles Chargers on Thursday night. Then they have a mini-bye before a Sunday night game at Seattle, then close the regular season with what should be a gimme game at home against the dreadful Raiders.

If the Chiefs had lost to the Ravens and the Patriots had held on against the Dolphins, the postseason outlook in the AFC would have been quite a bit different by late Sunday afternoon.

“I’m telling you,” Romo said during the Chiefs-Ravens broadcast, “this Kansas City comeback is incredible.”

Indeed it was.

And if the Chiefs end up in the Super Bowl, the events of Sunday afternoon in Kansas City and Miami will be worth remembering.