FOXBOROUGH, Mass. — Patrick Mahomes’ magic couldn’t run out. Not yet.

Down seven in a hostile stadium with time running out, Mahomes willed his team to keep working, to keep searching for a way to fight back and extend the the Chiefs’ undefeated season.

He quickly located Tyreek Hill and connected with the speedy wide receiver on the first play of the Chiefs’ drive for a 75-yard touchdown with a little more than three minutes left in an epic Sunday night showdown.

All the way back from a 15-point halftime deficit and a fourth-quarter one-score hole.

The almost-rookie was going toe-to-toe with a future Hall-of-Fame quarterback in his house, in front of his rabid fans.

In case there was any small shred of doubt before this, Mahomes is the real deal.

But so is Tom Brady, and so are the Patriots.

And Sunday night, that experience trumped the upstart boy wonder.

Brady hit Rob Gronkowski for a 39-yard reception with 40 seconds left. The big gain set up a 28-yard field goal for the Patriots as time expired.

It might not always be this way, but it was Sunday night as the Chiefs (5-1) lost their first game of the season 43-40.

It was Brady’s 200th win, and Mahomes’ first loss as a starter. It also denied Chiefs coach Andy Reid his 200th career win as a coach in the NFL.

To even get to that point, the Chiefs had to quickly atone for a first half of stalled out offense where they made four red zone trips and came away with three field goals. And a first half where the Chiefs’ defense allowed the Patriots’ offense to roll up 190 yards — including 83 on the ground.

Mahomes looked jittery and too hyped up in the first half as he overthrew his receivers and forced a couple passes. For the first time this season, Mahomes’ youth truly looked like it was catching up to him.

His third interception of the season turned into his costliest as he targeted Travis Kelce on his first throw of the Chiefs’ second drive. But Mahomes never saw Dont’a Hightower in zone coverage underneath. Hightower easily snagged the ball and returned it 27 yards toward the end zone. Rookie Sony Michel punched it in a play later from four yards out.

His second interception came at the end of the second quarter as he tried to thread the needle to Kelce in the end zone. But the ball ricocheted by Kelce and fell in Duron Harmon’s hands with a few seconds left until halftime.

Mahomes shook off a poor first-half performance for a second half that looked more like the Mahomes of the first quarter of the NFL season.

Starting with the ball in the third quarter, Mahomes hit Kareem Hunt (10 carries, 80 yards; 5 receptions, 105 yards, 1 TD) for a 67-yard touchdown on third-and-two just a minute and a half into the period.

He didn’t stop there, hitting Hill for the first of Hill’s three touchdowns later in the third quarter.

Mahomes found Hill two more times in the fourth quarter, including the 75-yard score to breathe life into his team.

Like Mahomes and the Chiefs’ offense, the defense found a better rhythm in the second half.

The defense gave up 24 points in the first half, including four straight scoring drives. Three of those went for touchdowns and the final one was a field goal.

Down five starters by halftime, the Chiefs had to rely on a cast of replacements to fill in for crucial players. KC started out the game without Houston, Eric Murray, Laurent Duvernay-Tardif and De’Anthony Thomas. Speaks, safety Jordan Lucas, offensive lineman Jordan Devey and kick returner/CB Tremon Smith started in their places, respectively.

In the second quarter, center Mitch Morse went out with a concussion, moving Jordan Devey to center and Andrew Wylie to right guard.

The replacements played key roles, including Smith, whose 97-yard kickoff return set up Hill’s second touchdown to give the Chiefs a three-point lead.

But on a night where the Patriots (4-2) had the magic and the momentum on their side, it just wasn’t enough.