Deebo Samuel ran for two touchdowns before leaving with an injury and Elijah Mitchell ran for 133 yards and a score, leading the San Francisco 49ers to a 34-26 victory over the Minnesota Vikings on Sunday.

The matchup between two .500 teams fighting for wild-card spots was a highly entertaining one with six scores in the third quarter alone, including a 99-yard kickoff return score by Minnesota’s Kene Nwangwu.

But the 49ers (6-5) made just enough plays, including a fourth-down stop near the goal line midway through the fourth quarter to win their third straight following a stretch of five losses in six games.

Also read: NFL: Green Bay Packers QB Aaron Rodgers suffered toe injury but expected to play

Jimmy Garoppolo threw for 230 yards and a TD, but the Niners once again did more of their work on the ground with Samuel’s two scores making him the first receiver since the merger to run for five TDs in a season. Samuel had six carries for 66 yards and also caught one pass for 15 yards before leaving with a groin injury.

San Francisco finished with 208 yards rushing on 39 carries.

Kirk Cousins threw for 238 yards and two TDs to Adam Thielen for the Vikings (5-6). But he also had an interception that set up a short San Francisco scoring drive in the third quarter and couldn’t connect with Justin Jefferson on the fourth down from the 3 after burning a timeout when he lined up under the guard instead of the center.

The Niners drove down into field-goal range, but Robbie Gould missed from 42 yards with 1:56 left and a chance to put the game away.

Also read: NFL: Baltimore Ravens, Cleveland Browns to meet for first time since December clash

Minnesota drove to the San Francisco 38 before turning it over on downs when Cousins missed Jefferson on fourth-and-8.

Quick strike:

The 49ers scored twice in a 22-second span of the third quarter starting when Samuel capped the first drive of the half with a 3-yard run.

Azeez Al-Shaair got an interception on the next play from scrimmage, capping Cousins’ streak of 212 straight passes without an interception.

Also read: Detroit Lions’ winless streak continues after 16-14 loss vs. Chicago Bears

Mitchell ran it in from 6 yards on the next play.

Scoring late:

The Niners used an 87-yard drive to tie the game late in the second quarter on Garoppolo’s 3-yard pass to Jauan Jennings with 18 seconds left in the half.

The Vikings have allowed 66 points in the final two minutes of the first half, the most for any team through 11 games since at least 2000.

Playing from ahead:

The Vikings scored on their second drive of the game when Cousins hit Thielen on a 2-yard pass on fourth-and-goal to take a 7-0 lead. That made Minnesota the 17th team in the Super Bowl era to take a lead of at least seven points in each of the first 11 games.

Also read: Packers QB Aaron Rodgers says he has been playing with a fractured toe

The first 16 teams to do it combined for an .852 winning percentage. The Vikings are the only team to do it and have a losing record.

Key injuries:

Vikings: RB Dalvin Cook (shoulder) left the game after getting hurt in the third quarter when he lost a fumble. … LB Anthony Barr (hamstring) also left in the third quarter.

49ers: LB Dre Greenlaw (groin) and RB Trey Sermon (ankle) left the game with injuries in the first half and didn’t return. Greenlaw was back for his first game since injuring his groin in the season opener. … LB Fred Warner (hamstring) left in the second half.

Up next:

Vikings: Visit Detroit on Sunday.

49ers: Visit Seattle on Sunday.