INDIAN WELLS, Calif. — Roger Federer was on the ropes, down two breaks in the second set and another one in the third. Borna Coric thought he was close to toppling the world's top-ranked player.

Not so fast.

Federer rallied for a 5-7, 6-4, 6-4 victory in the BNP Paribas Open semifinals on Saturday, extending his career-best start to 17-0 and giving him a chance to win his record sixth title.

"I went for my shots. I was not waiting. I made the right choices all the time," Coric said. "He was just a better player in those specific moments. At the end, he just got through."

Barely.

"I should have lost a match," Federer said.

He will meet No. 6 Juan Martin del Potro in Sunday's final. The Argentine breezed past No. 32 Milos Raonic of Canada 6-2, 6-3 in 66 minutes for his 10th consecutive match victory and 400th of his injury-plagued career.

"It was surprising to see him serving not too hard, and I broke his serve very quick in both sets," Del Potro said. "That gave me the control of the match."

Federer is 18-6 in his career against del Potro, with two of the losses coming at the U.S. Open, in the 2009 final and last year's quarterfinals.

"I love to play against him," Del Potro said. "It will be a good challenge to see how my level is against him."

Federer rallied from a 5-7, 2-4 deficit to win the final four games of the second set, breaking Coric twice for the first time in the match.

"It didn't come easy, so I had to go get it," Federer said. "You need to be match-tough, you need to be confident, have experience, and I think I have a bit of all of that right now, and that's the reason I won."

There were five breaks in the third. Federer trailed 4-3 and then broke after two deuces on his way to winning the last three games of the two-hour, 20-minute struggle.

"That's why he's champion," Coric said.

Coric's crosscourt forehand was called out on match point. He challenged the call and the line system showed it was just wide of the sideline.

"I was aggressive and I was pushing him to the limits, but at the end he was better player," Coric said. "I thought he was going to drop, but he didn't. He stayed in the match very, very long, and I just couldn't keep it up anymore."

Federer hasn't started a season so well since 2006, when he won his first 16 matches en route to a 92-5 record.

The Swiss superstar was playing a rare 11 a.m. match. According to the ATP Tour, Federer hadn't played that early since 2006. And it showed as he sprayed errors all over the court and didn't break Coric for the first time until late in the second set.

"Really I just woke up," Federer said in an on-court interview. "It was early today. I had pasta at 9:15. It was yummy."

Until losing the first set, Federer hadn't dropped a set in the tournament.

Trailing a set and 0-2 in the second, the crowd, including Rod Laver and Pete Sampras, seemingly tried to will better shots out of Federer with loud applause and shouts of encouragement.

"Borna played a great match. He was very steady," Federer said. "I can see why he caused a lot of problems to a lot of players, and he's only going to improve from here."

Coric, a 21-year-old from Croatia, was in his first ATP Masters 1000 semifinal. He will jump 13 spots to No. 36 in Monday's ATP World Tour rankings.

Federer, No. 1 again at 36, owns 27 career Masters 1000 titles.

Coric is part of a trio of 20-somethings that have dominated the desert tournament. Daria Kasatkina of Russia and Naomi Osaka of Japan, both 20, will meet in the women's final on Sunday after knocking out several higher-ranked players along the way.

Del Potro has fought back from left wrist surgeries in 2014 and 2015 (twice) and another one on his right wrist in 2010 that nearly caused him to quit tennis. He is 16-3 this year with one title in Acapulco.

"I didn't play him before his injuries, but his backhand was probably one of the things that was overlooked because the forehand was so hard," Raonic said. "But the backhand, I remember when he won the U.S. Open, he could hit it crosscourt without any guys being able to have the freedom of running around or anything. He's gotten that back quite a bit."

___

More AP tennis coverage: https://apnews.com/tag/apf-Tennis