FOXBORO (CBS) — With the way that Sunday’s game began, it looked like the Patriots would not have a chance vs. the Cardinals. And with the way things turned sour again late in the fourth quarter, the Patriots again looked doomed.

Yet somehow, some way, the Patriots managed to pull off an improbable 20-17 victory.

READ MORE: Large Fire Erupts In Everett At Schnitzer Scrap Metal Site

The Cardinals lined up for a 45-yard field goal to take the lead with less than two minutes to play, but Zane Gonzalez’s kick sailed right. The Patriots took over at their own 35-yard line.

On the resulting drive, Cam Newton took off running on a third-and-13 for a 14-yard gain. A 15-yard penalty on Isaiah Simmons for unsportsmanlike conduct was tacked on to the play.

Nick Folk came on to attempt a 50-yard field goal as time expired, and it sailed through the uprights, giving New England a 20-17 victory.

Newton completed just nine of his 18 passes for 84 yards with no touchdowns and two interceptions. He did run for 46 yards on nine carries and came up with that game-changing run on the game-winning drive.

Kyler Murray was 23-for-34 for 170 yards with no touchdowns and one interception, while rushing for 31 yards on five carries.

The Patriots got off to a disastrous start. Newton was hit as he threw by a blitzing Jordan Hicks on third-and-6 on the opening possession. The ball popped out of Newton’s hands and into the arms of linebacker Markus Golden.

Murray gave a quick shovel pass to Andy Isabella on the Cardinals’ first snap after the turnover, and the UMass product turned the corner around the left side and scampered for a 19-yard gain to get the ball to the New England 4-yard line. Kenyan Drake took back-to-back handoffs, scoring on the second run and giving Arizona an early 7-0 lead.

The Patriots were forced to punt on their second drive, with Jake Bailey’s booted ball coming to rest at the Arizona 3-yard line. The Cardinals managed to drive to the New England 27-yard line before having to settle for a 47-yard field goal from Zane Gonzalez to take a 10-0 lead late in the first quarter.

The Patriots’ offense finally got rolling on their third drive, thanks in large part to a 53-yard kick return by Donte Moncrief. Boosted by that starting field position, the Patriots drove to the Cardinals’ 8-yard line. On third-and-3, Gunner Olszewski was stopped after a gain of just one yard on a jet sweep. Bill Belichick opted to keep the offense on the field for fourth-and-2, and an option pitch from Newton to James White resulted in the running back planting his right leg before cutting up the field for a seven-yard touchdown run.

READ MORE: Kurt Warner Wants To See Patriots-Buccaneers Super Bowl: 'It's Not Just A Pipe Dream'

Nick Folk’s extra point cut Arizona’s lead to 10-7 in the opening minute of the second quarter.

The Cardinals appeared to have stretched their lead to double digits before halftime, but KeeSean Johnson’s touchdown was taken off the board after replay showed he was down at the 1-yard line. The Cardinals decided to go for it on fourth-and-goal from the 1-yard line, but Ja’Whaun Bentley and Akeem Spence combined to put up a wall at the goal line to stop Drake short of the goal line. After replay review confirmed the stop, the teams headed to the locker rooms, with Arizona leading 10-7.

The second half began with Murray scrambling toward midfield but giving himself up two yards shy of the line to gain. Arizona punted on that opening possession, and Olszewski returned it 82 yards for a touchdown. However, rookie linebacker Anfernee Jennings was flagged for delivering a blind-side block at the 24-yard line, giving possession to the Patriots at the Arizona 39-yard line.

The Patriots got down to the Arizona 4-yard line, but a pressured Newton threw incomplete on third down, and New England settled for a field goal to tie the game at 10-10 midway through the second quarter.

New England got another short field shortly thereafter, when Adam Butler deflected a third-down pass from Murray. Adrian Phillips intercepted that pass, and the Patriots took over at the Cardinals’ 31-yard line.

New England capitalized on this one, with White scoring his second touchdown of the day on a sweep to the left side from the 1-yard line. The PAT gave the Patriots their first lead of the day at 17-10.

The Cardinals tied things up, though, thanks in large part to Jason McCourty committing a holding penalty against Dan Arnold on what looked to have been a fourth-and-5 stop by the Patriots’ defense. Instead, the Cardinals got a fresh set of downs, and that was refreshed once again when Stephon Gilmore got called for defensive holding against DeAndre Hopkins in the end zone on a third-down incompletion.

Drake burrowed into the end zone on a second-and-goal from the 1-yard line, and the game was tied at 17-17 with 8:02 left in the fourth quarter.

The Patriots’ attempt to regain the lead was thwarted when Newton threw an ill-advised pass to a well-covered Damiere Byrd with 4:30 left in the fourth quarter. Cornerback Dre Kirkpatrick easily stepped in front of the receiver to intercept the pass, returning it 13 yards to set the Cardinals up near midfield. The Cardinals, though, couldn’t capitalize on that turnover.

The win improves the Patriots’ record to 5-6 on the season.

MORE NEWS: When Will The Snow Start? Massachusetts' First Widespread Snow Of Season Could Impact PM Commute

The Patriots will now embark on a stretch of the schedule that entails three straight road games. They’ll face the Chargers in L.A. on Sunday before staying in town to face the Rams the following Thursday. The Patriots will then travel to Miami to face the Dolphins in Week 15.