At the lowest points of an 18-month struggle with left knee and hip problems, Brooks Koepka wondered if he’d ever be back, let alone recapture the magic that carried him to four major championships.

“It’s been a wild ride for the last year and a half and very frustrating,” Koepka said. “I’ve had moments where I didn’t know if I was going to be the same, if I could even come back.”

He looked as good as ever on the back nine Sunday in the Waste Management Phoenix Open, rallying for a victory that didn’t seem possible not that long ago.

“I went through it mentally,” Koepka said. “I think that’s probably the toughest thing, where you don’t know if you’re ever going to be the same competitor that you were. You go through some real dark places, and it’s not a fun place to be.”

It was sunny and fun Sunday in the desert, especially on the 17th hole. That’s where he chipped in from 32 yards for his second eagle of the day to break a tie for the lead. A routine par on the 18th gave him a 1-stroke victory.

Five strokes behind Jordan Spieth and Xander Schauffele entering the round, Koepka shot a 6-under 65 to finish at 19-under 265. He also won in 2015 at TPC Scottsdale for the first of his eight PGA Tour titles.

The 5-stroke comeback was the largest by any tournament winner in the past two seasons, according to ESPN Stats & Information research.

On the 334-yard 17th, Koepka hit a fairway wood 305 yards to the fairway short and left of the green, then holed out to the largest roar of the day from the crowd limited to 5,000 a day.

“I felt like the chip, if I just caught it right in the fringe, it was going to check up on me, and it did perfectly,” he said. “Took a nice little right kick for me and didn’t look anywhere else but the hole.”

Coming off a career-worst three straight missed cuts, Koepka rebounded from a bogey on the second with a 24-foot eagle putt on the par-5 third and birdied Nos. 13, 14 and 15.

“I live for those moments where you got to close, you got to hit some quality shots, quality putts,” Koepka said. “I just like showing off, I guess.”

Schauffele birdied the par-4 18th for a 71 to tie for second with Kyoung-Hoon Lee (68). The fourth-ranked Schauffele tied for second last week at Torrey Pines.

“It was a good day to learn from some mistakes,” Schauffele said. “Felt like I stayed pretty patient all day.”

Spieth and Schauffele struggled from the start, with Spieth bogeying the first hole after nearly driving into a desert bush. They each had two bogeys on the front nine, with Schauffele making the only birdie between the two on the front side on No. 9.

Schauffele and Spieth each drove into the water on 17 to end their chances, then both birdied 18.

Spieth shot 61 on Saturday for a share of the lead. Winless since the 2017 Open, the 27-year-old Texan is trying recapture the form that carried him to 11 PGA Tour victories — three of them majors — in his first five seasons on tour.

“I just wanted to potentially go home and felt like I was really far from where I needed to be,” Spieth said, “and this golf course in general isn’t a great golf course for me historically, so I thought I could then go in to Pebble [Beach] a little fresher. Boy, I’m glad I came.”