INDIAN WELLS, Calif. (AP)—Rafael Nadal’s serve deserted him in the second set, and so did his chances of beating a streaking Novak Djokovic.

Djokovic defeated the world’s top-ranked player 4-6, 6-3, 6-2 to win the BNP Paribas Open title on Sunday, keeping the Serbian perfect this year.

Djokovic improved to 18-0, including victories at the Australian Open and in Dubai last month.

“It definitely says good things. I am playing with a lot of confidence. I’m feeling the ball well on the court,” he said. “I’m very dedicated. I have a big will to win each match. I want to keep on going and keep on playing good tennis.”

Djokovic will move into the No. 2 spot when the ATP Tour rankings are released Monday, having bumped Roger Federer down to third after he lost to Djokovic in the semifinals. Nadal will remain No. 1 with a 14-3 record.

After Nadal’s forehand hit the net on match point, Djokovic threw his head back and let out a prolonged yell while pumping both arms.

His Monte Carlo neighbor, top-ranked Caroline Wozniacki, defeated 15th-seeded Marion Bartoli 6-1, 2-6, 6-3 to win the women’s title a year after the Dane lost in the final.

Djokovic became just the third player to beat Nadal and Federer in the same tournament twice, having last done it at Montreal in 2007. That year, Djokovic lost to Nadal in the final at Indiana Wells, then won in 2008.

“I know that the season is very long and I don’t want to be too euphoric about the win,” said Djokovic, who plays at Miami this week. “I need to celebrate a little bit and then move on.”

Nadal had beaten Djokovic in all five of their previous finals meetings, and he broke him twice to win the first set.

Djokovic broke to lead 5-3 in the second set, then survived a five-deuce game on his serve to take the set, winning when Nadal’s backhand went wide. It was the first of six straight games he’d win as the Spainard’s first-serve percentage dipped to 25 percent.

“At the end of the first set, I started to serve really bad, and the second set still in the beginning, even if I won the games because he had more mistakes than usual with the second serve return, I play less aggressive,” Nadal said. “I was thinking too much about the serve more than the game in that moment, so I stop a little bit the legs. The serve was the difference.”

Djokovic broke an error-prone Nadal twice in the first three games of the third set to take a 4-0 lead. Djokovic served out the match at 40-love to keep Nadal without a title since October.

Wozniacki won her WTA Tour-leading 19th match of the year and her second title while appearing in the final for her third consecutive tournament.

Wozniacki won on her second match point when Bartoli’s backhand sailed beyond the baseline. Bartoli was playing in her first final since 2009, and she fell to 2-6 in matches against the No. 1 player.

The victory allowed Wozniacki to improve her results for the fifth straight year in the desert. She lost in the first round in her 2007 debut, reached the fourth round in 2008, the quarterfinals in 2009 and was runner-up to Jelena Jankovic a year ago.

She earned $700,000, and was already assured of remaining No. 1 through the upcoming two-week tournament in Miami. Bartoli is projected to be No. 10 when the rankings are released Monday, her first time back in the top 10 since June 2008.

“If every single match I could play like that throughout the years, I would be pretty happy,” Bartoli said. “Even though I came up a bit short at the end and she was better than me, I think it was really a great fight.”

Wozniacki rolled through the first set, breaking Bartoli three times with well-placed shots that jerked her from side to side and up and back. Bartoli was breathing heavily throughout the match that was played in 65-degree temperatures under overcast skies.

“I can keep playing out there for hours and hours,” Wozniacki said. “It’s definitely a good sign for me when I can see the opponent getting a little bit more tired. We had a lot of long rallies, but I felt like I recovered maybe a little bit faster than she did. That’s a good feeling to have on my side.”

Bartoli earned the only two breaks of the second set, when Wozniacki seemed content to stay back and rally instead of trying to go for as many winners as she did in the opening set.

“She just went for her shots. She started to hit even harder,” Wozniacki said. “I didn’t feel I played badly. I thought actually I played pretty good, but she was very steady, keeping the pressure.”

Wozniacki broke Bartoli after two deuces to open the third. She owned triple break point in the third game, but missed a forehand that allowed Bartoli to hold trailing 2-1. Bartoli was the first Frenchwoman to make an Indian Wells final.

Wozniacki got broken for the only time in the third on a missed backhand and Bartoli survived a deuce game on her serve to close to 4-3.

But Wozniacki won the final two games, breaking Bartoli to close out the match.