BOSTON (CBS) — That was long. It was difficult. And it was ugly.

But when the clock hit zero on Sunday afternoon in Houston, the Patriots had themselves a victory.

Despite falling behind 6-0, and 15-6, and 22-9, the Patriots played a nearly perfect final 25 minutes to escape Houston with a 25-22 win.

Nick Folk kicked a chip shot from 21 yards out with 17 seconds left in the game to give the Patriots their first lead of the game.

Mac Jones completed 23 of his 30 passes for 231 yards with one touchdown and one interception.

Damien Harris ran for 58 yards and a touchdown on 14 carries, while Brandon Bolden ran for 25 yards on just two carries, and Rhamondre Stevenson had 23 yards on 11 carries. Hunter Henry caught six passes for 75 yards and a touchdown.

Folk successfully kicked all four of his field goal attempts in the win.

For Houston, Davis Mills completed 21 of his 29 passes for 311 yards with three touchdowns.

The Texans opened the game with a marathon drive, going 79 yards on 18 plays and capping it off with an 11-yard touchdown pass from Mills to Anthony Auclair.

That drive was kept alive by a pass interference penalty on J.C. Jackson against Brandin Cooks on a third down incompletion. Ka’imi Fairbairn missed the PAT.

The Patriots answered right back with a 10-play, 60-yard touchdown drive, which ended with Damien Harris taking a direct snap with Jones split out wide, before rushing in for a 1-yard score. Jones was 2-for-2 for 26 yards on third down on that drive, and 3-for-3 for 32 yards overall on the team’s first opening drive touchdown of the season. Nick Folk missed his PAT, too, making the score 6-6 early in the second quarter.

It did not take long at all for the Texans to come back, though, as Mills threw to Chris Moore on a third-and-2, just over the leaping arm of J.C. Jackson up the right sideline. Moore came down with the ball and then took off untouched for a 67-yard touchdown.

Fairbarn missed another PAT, making the score 12-6 in favor of the Texans.

The Patriots then marched right back down the field, scoring what appeared to have been a touchdown to tie the game with a chance to take the lead with a PAT. But after replay review, the NFL ruled that Harris fumbled the football before crossing the goal line. The Texans recovered that ball, taking points off the board for New England and giving possession to Houston.

The Texans then drove for a field goal to stretch their lead to 15-6, but Folk drilled a 52-yard field goal before halftime to cut it to 15-9.

Things went from bad to worse, when Jones’ first pass of the second half was off the mark and was intercepted by Lonnie Johnson Jr.

The Texans immediately cashed in, with Mills throwing a 37-yard touchdown to Chris Conley off a flea flicker two plays later.

The Patriots benefited from a special teams gaffe by Houston, as punter Cameron Johnston kicked the ball into a teammate’s helmet after some pre-snap tomfoolery, but they only got a field goal out of that opportunity, making it a 22-12 game in the third quarter.

New England added another field goal late in the third quarter after a 47-yard drive to cut Houston’s lead to seven points.

Fairbarn missed a 56-yard field goal early in the fourth quarter, his third missed kick of the day, this time giving New England prime field position on the potential game-tying touchdown.

The Patriots capitalized, getting into the red zone with 31 rushing yards and a 10-yard pass from Jones to Hunter Henry. When faced with a third-and-6 at the 13-yard line, Jones went back to Henry, lobbing a ball to the corner of the end zone and allowing the tight end to get it.

Henry caught the TD, folk hit the PAT, and the game was tied at 22-22.

The Patriots’ defense then forced a three-and-out, before the Patriots marched 84 yards on 15 plays to kick the game-winning field goal. That drive was kept alive by a roughing the passer penalty on Maliek Collins on a third-down incompletion by Jones.

The 2-3 Patriots will host the Cowboys next Sunday at Gillette Stadium. Staff