KANSAS CITY, Mo. — Patrick Mahomes dazzled in the first half of his Arrowhead debut, but it was ultimately up to the defense to get a crucial stop in the fourth quarter to preserve the Chiefs' 38-27 win over the 49ers on Sunday.

That the Chiefs (3-0) were even in this predicament after leading 35-7 was largely a byproduct of shaky defense in the second half, but the unit recorded back-to-back sacks and a monster hit on quarterback Jimmy Garoppolo with 6 minutes to go in the fourth quarter to prevent the game from becoming a one-score affair.

The hit by Steven Nelson on Garoppolo brought on the 49ers backup quarterback CJ Beathard, who looked to have a touchdown throw, but fullback Kyle Juszczyk was called for offensive pass interference, nullifying the score.

Instead, the 49ers decided to end an 8-minute scoring drive with a field goal.

The Chiefs' first half lived up to the hype. With 295 yards and five touchdowns, KC kept the momentum rolling from the first two weeks.

Every facet of the offense got involved from the very beginning. Kareem Hunt got things going with two first-quarter 1-yard rushing touchdowns _ the Chiefs' first ground scores of the year.

Then the Chiefs spread the ball around to Sammy Watkins, Travis Kelce and Tyreek Hill. By halftime, Kelce was knocking on the door of a 100-yard game, a mark he surpassed in the third quarter.

Unlike the first two games, the Chiefs put together two slow, methodical drives to get their first two scores. The first went 57 yards over 11 plays in 4:55, and the second was a little more efficient at eight plays in 3:26 to cover 84 yards.

The 49ers answered on the next series with a 35-yard touchdown throw to fullback Kyle Juszyzck.

But the Chiefs went up by another score as Mahomes rifled a pass to Chris Conley midway through the second, getting the throw off as he scrambled around to shake the 49ers pass rush. The wide receiver caught the ball in the end zone for the Chiefs' third score of the game. Mahomes finished 24 for 38 passing for 314 yards and three touchdowns.

Demetrius Harris pitched in next, catching his first touchdown of the season, and Watkins followed up with his first touchdown catch as a Chief.

At halftime, the Chiefs were dominating in every way. The 49ers had 179 yards of offense and nine penalties for 106 yards.

But momentum swung the other way when Harris dropped a pass on third down in the Chiefs' first possession of the third quarter. That brought out Dustin Colquitt for the first time Sunday afternoon as the Chiefs punted the ball away.

The 49ers capped off the corresponding drive with an 11-yard touchdown pass to Marquise Goodwin where the receiver was wide open. The closest players around him were his own teammates. But the 49ers failed to completely capitalize on the opportunity, missing the extra point.

The Chiefs couldn't recreate the offensive magic of the first-half and went three-and-out before giving the ball back to the 49ers in Colquitt's second punt of the day.

By the end of the third quarter, the 49ers had scored 17 unanswered points.

The Chiefs and Dolphins are the AFC's only remaining undefeated teams.