MINNEAPOLIS >> Dan Campbell called it.

Earlier in the week, the Detroit Lions head coach said no matter what happened through the first three quarters of Sunday’s pivotal division matchup against the Minnesota Vikings, he wanted his team to keep its composure and have a chance to win it in the fourth quarter.

And that’s exactly what happened in the Lions’ 31-29 victory at U.S. Bank Stadium.

After a costly fumble by running back David Montgomery that the Vikings returned for a touchdown, the Lions’ defense got a stop when it needed to and held on just long enough for rookie kicker Jake Bates to drill a 44-yard field goal that pushed Detroit to first place in the NFC North and handed the Vikings their first loss of the season.

“We knew they were going to be ready and it was going to come down to the wire. The team knew this. We talked about patience … keep your composure, communication, and an attitude,” Campbell said. “Our guys did that. We hung in there. We didn’t bat an eye.”

Detroit (5-1) rallied back from an early 10-point deficit with 21 unanswered points in the second quarter before watching their two-score, second-half lead slip away following a hectic back-and-forth sequence in the fourth quarter. Detroit’s defense held Minnesota to consecutive field goals in the fourth quarter, but it was the offense that nearly cost them the game after a scoop-and-score touchdown from Vikings defender Ivan Pace Jr. gave Minnesota (5-1) a 29-28 lead with 5:50 to go.

After the two teams exchanged three-and-outs, the Lions got the ball back at their own 30-yard line with 2:32 left in a one-point game. Detroit got a couple of big plays from running back Jahmyr Gibbs and receiver Amon-Ra St. Brown to move to the Vikings’ 21-yard line with 1:07 remaining and eventually capitalized on the opportunity with the field goal from Bates.

“We knew the whole week was about composure,” said Lions quarterback Jared Goff, who had another perfect 12-for-12 first half and went on to finish 22-for-25 passing for 280 yards and two touchdowns.

“We go down, 10-0, and we’re kind of getting kicked in the mouth a little bit; stay calm, stay relaxed. We have the fumble, they score on us; stay calm, stay relaxed, one play at a time. It really came in handy for us late in the game.”

The kick was a massive moment for Bates, who has begun his first NFL season a perfect 10-for-10 on field goals, including the latest and greatest in front of a raucous Vikings crowd that was desperate to see him have his first miss.

“It’s definitely the loudest environment I’ve ever kicked in,” Bates said.

But he stayed calm, stayed relaxed. And got a little bit of help from his favorite Bible verse, Hebrews 12:1. “Therefore, since we are surrounded by such a great cloud of witnesses, let us throw off everything that hinders and the sin that so easily entangles. And let us run with perseverance the race marked out for us,” the verse reads.

“At the end of the day, it’s doing the same job that I’ve prayed for for so long and worked so hard for,” Bates said. “So, I mean, if you let that get too big in the moment, it’s probably going to get too big for you.”

Following Bates’ field goal with 15 seconds remaining, the Vikings had a chance to create a miracle going back the other way. Minnesota was granted the opportunity to run a Hail Mary with one second remaining, despite not being properly set for a spike before the play, which drew a flag.

But on a day when the absence of injured defensive end Aidan Hutchinson was glaring, it was another local kid, linebacker Trevor Nowaske (Salem High School/Saginaw Valley State), who sealed the win with a sack of Vikings quarterback Sam Darnold as time expired.

Gibbs was sensational for Detroit. He totaled 160 yards from scrimmage (116 rushing, 44 receiving) and averaged 8.4 yards per touch with two touchdowns. His first score came on a 45-yarder, the longest run of his career, with the Lions’ offense desperately trying to break through after starting the game 0-for-3 on third downs.

St. Brown was a vintage version of himself: He caught eight passes for 112 yards and a second-quarter touchdown that gave Detroit a 14-10 lead at 8:39 in the second quarter.

Lions safety Brian Branch, who had two interceptions in the team’s Week 6 win over the Dallas Cowboys, intercepted his fourth pass of the season at 5:39 in the second quarter to stop the Vikings in Detroit territory.

The interception was a timely one, too: Detroit nearly held the ball for the remainder of the second half and was able to take a two-score lead with 23 seconds left, when Gibbs scored his second touchdown of the day on an 8-yard run.

“Confidence is going sky high,” Campbell said of Branch. “He’s getting better and better. He’s still kind of young and new to the safety position for us. Sometimes you forget that. … He’s the ultimate football guy. He understands how to play the game. He’s instinctive. He’s tough. He’s smart. He’s a great tackler. He’s a ball guy. He’s got radar.

“He’s one of those guys that can change the game for you.”

Aside from the interception, Vikings quarterback Sam Darnold was locked in. He finished 22-for-27 passing for 259 yards and a touchdown, with 81 yards coming from Justin Jefferson and 76 for former Michigan State receiver Jalen Nailor. Vikings running back Aaron Jones gashed the Lions’ vaunted run defense with 93 yards on 14 attempts.

But the Lions got the stops they needed.