MINNEAPOLIS — The Detroit Lions became division champions for the first time in 30 years late last season with a clinching win at Minnesota. They departed this time with another memorable and resilient performance — plus a big boost in their pursuit of another NFC North title.

Jake Bates kicked a 44-yard field goal with 15 seconds left in the Lions ‘ 31-29 victory on Sunday, handing the Vikings their first loss in a back-and-forth game befitting of the NFL’s strongest division.

“We talked about patience, keeping your composure, communication and an attitude, and our guys did that,” coach Dan Campbell said. “We didn’t bat an eye when things appeared to start going a little south.”

Jahmyr Gibbs rushed for 116 yards and two of Detroit’s three second-quarter touchdowns. He also helped Jared Goff guide the Lions 48 yards in four plays to get in range for their rookie kicker while forcing the Vikings to burn their timeouts.

Bates, who was plucked from the United Football League after Michael Badgley got hurt at the beginning of training camp, is 10 for 10 on field goals this season.

Goff went 22 for 25 for 280 yards with touchdown passes to Amon-Ra St. Brown and Kalif Raymond and no turnovers.

“He doesn’t get frazzled. He’s competitive, and he’s reliable,” Campbell said.

Gibbs had 150 total yards to spearhead a commanding performance by the Lions (5-1) at the line of scrimmage against the defense that entered the week with a rushing average per play (3.6) allowed that was the second-best in the league.

“He’s been so close to exploding,” Campbell said, “and we felt like this was the game.”

Ivan Pace Jr. returned David Montgomery’s fumble 36 yards for a touchdown with 5:50 remaining to give the Vikings (5-1) a one-point lead after they trailed 21-10 at halftime, but Sam Darnold’s crucial 2-point conversion pass sailed past Justin Jefferson.

The Vikings reached midfield on their last-gasp possession, but an illegal formation penalty on left tackle Christian Darrisaw after the hustle to get set pushed them out of range for their own perfect rookie Will Reichard to attempt a field goal. Darnold was sacked to end the game and give the Lions their fourth consecutive victory over the Vikings.

The Lions are tied with the Vikings, with the Green Bay Packers (5-2) a half-game back and the idle Chicago Bears (4-2) one game behind.

Aaron Jones rushed for 93 yards and a TD for Minnesota. Jefferson had 81 yards receiving and a score, and Reichard made three field goals, including a 57-yarder.

Darnold went 22 for 27 for 259 yards, but he spoiled a promising drive in the second quarter by ignoring a wide-open Jones in the flat off a play-action fake and forcing a throw to Jordan Addison that was intercepted by a diving Brian Branch.

The Lions played a second quarter for the ages. They had three scoring drives that all covered at least 69 yards on the strength of some shrewd play-calling by offensive coordinator Ben Johnson that rendered the chess moves by Vikings defensive coordinator Brian Flores moot, as Goff beat blitz after blitz.