SANTA CLARA >> Fred Warner’s interception return delivered the 49ers’ first touchdown of Sunday’s triumph, and a cinematic goal-line dive completed a highlight-reel play by the NFL’s most dominant defender.

Then it was Warner’s turn to watch Sunday’s other highlights (and hiccups).

An ankle injury forced him to the sidelines as a lead of 20-0 was halved to 20-10. Instead of repeating last Sunday’s collapse in Los Angeles, the 49ers finished off the New England Patriots 30-13 at Levi’s Stadium.

The 49ers (2-2), who snapped a two-game losing streak, return to their home field next Sunday to host Arizona (1-3) — an NFC West matchup in which Warner’s presence certainly will impact the Cardinals’ combination of Kyler Murray and Marvin Harrison Jr.

Series after series, Warner and the 49ers stymied the Patriots en route to a 20-0 lead, with no signs of defensive deficiencies that marred their road losses to the Minnesota Vikings and the Rams the previous two Sundays.

The 49ers produced six sacks and forced three turnovers, the last of which came on Nick Bosa’s strip-sack fumble recovery in the final three minutes. The Patriots’ points all came after Warner left for the locker room before halftime.

“The defense was awesome all day,” coach Kyle Shanahan said. “Anytime you score, even better.”

With the 49ers initially settling for two field goals and a 6-0 lead, Warner equaled that point output with a 45-yard interception return for his second career touchdown. He cited his experience in knowing “where to be in the right spot” to snare a third-and-5 throw, then, “as soon as I got up, I found some green grass,” and off he went toward an ultimate dive for the right pylon.

Warner would be gone before halftime because of his ankle injury, which he said will require testing to determine its severity but that he otherwise “feels good right now.”

The 49ers took a 20-3 lead into halftime once New England’s Joey Slye made a 63-yard field goal matched the fourth-longest distance in NFL history. Then, with Warner wanting to play and seemingly restrained by teammates on the sideline, the 49ers allowed a 5-yard TD catch to Stanford product Austin Hooper for a 20-10 margin.

The 49ers promptly launched a countermeasure in the form of Deebo Samuel’s 53-yard reception of Brock Purdy’s first-down bomb. That set up Jordan Mason’s 4-yard touchdown run for a 27-10 lead with 25 minutes to go. Purdy went deep a couple of more times, including a 45-yard completion to last game’s star, Jauan Jennings.

Purdy’s ability to scramble — twice for third-down conversions on the initial drive — served as reminders about his sneaky mobility, and George Kittle further reminded reporters that Purdy pulled off similar rambling rescues in January’s NFC Championship Game comeback.

“I feel I have just the right amount of athleticism to make plays,” Purdy said. “I don’t have to be a freak athlete. I know who I am. If something presents itself, I’ll do what I can to move the chains and help my team. ... I’m not Lamar Jackson by any means.”

Mason finished with his third 100-yard rushing game in four starts in place of Christian McCaffrey, who’s projected to resume his rehabilitation today from an Achilles issue. Mason had 24 carries for 123 yards, including a 25-yard gain on the penultimate snap.

The offense’s more artistic touchdown came from Kittle, who made a 12-yard scoring grab over three defenders for the 20-0 lead.

“I had a great view of it. I was amazed and speechless,” left tackle Trent Williams said. “That’s one of the greatest catches I’ve seen in person.”

Kittle was hesitant when he first heard the play call and double checked with Purdy.

“I wasn’t really confident in the play call because we originally called it further out,” Kittle said. “It was an out and up that we originally called from the 40. To run a 12-yard out-and-up from 10 yard line is a little aggressive, but what a great play call when it works.”

Kittle later headed to the locker room early with a rib injury but returned to action in the second half; he declined to reveal the nature or severity of his injury after the game.

Continuing a troubling trend, the 49ers got punished for a special teams gaffe: rookie Isaac Guerendo fumbled on the second half’s kickoff return, and the Patriots parlayed his turnover into Hooper’s touchdown three snaps later. “It was a big fumble to open it up in the third quarter and it gave them a chance right away,” Shanahan said.

The Patriots (1-3) came in overmatched and were even more so once center David Andrews (shoulder) and right tackle Caeden Wallace (ankle) exited with injuries. It became a two-score game, however, once New England got a 54-yard field goal with 13:26 remaining from Slye, who had a three-game cameo with the 2021 49ers. Jake Moody’s 41-yard field goal made it 30-13 with five minutes left.

Notes

Samuel returned from a one-game absence (calf), started at running back (two carries, 14 yards) and caught 3-of-5 targets for 58 yards. ... Jennings, after his three-touchdown outburst for 175 yards in Los Angeles, made three catches for 88 yards in his encore. ... Purdy completed 15-of-27 passes for 288 yards, with the touchdown to Kittle and a fourth-quarter interception on a lob toward Brandon Aiyuk. ... Aiyuk caught 2-of-5 targets for 48 yards, including a 38-yard diving grab. ... Credited with forced fumbles were Okuayinonu, Leonard Floyd and Evan Anderson.