LONDON (AP) — Novak Djokovic edged a bit closer to the year-end No. 1 ranking.

The second-ranked Serb beat Milos Raonic 7-6 (6), 7-6 (5) Tuesday to qualify for the semifinals of the ATP finals and improve his record against the Canadian to 8-0.

Djokovic is 2-0 at the season-ending tournament, and will retake the top ranking from Andy Murray if he does better this week. Murray is 1-0 so far, and plays his second match on Wednesday against Kei Nishikori.

Djokovic never looked at ease in his second match at the O2 Arena, but he was able to hang on through two tough tiebreakers to earn the victory.

"It really could have gone either way," said Djokovic, who completed a career Grand Slam by winning the French Open this year. "I was down very early in both tiebreaks tonight. But I just managed to stay committed and put pressure on his second serves."

To get to the tiebreakers, Djokovic saved three break points in the first set. He then managed to go up a break twice in the second set, but Raonic responded each time.

Raonic, who reached the Wimbledon final this year, took the lead in both tiebreakers as Djokovic struggled for consistency, but he couldn't hold on.

"I gave myself some chances there. He played well in most of those chances," said Raonic, who can still advance to the semifinals by beating Dominic Thiem on Thursday. "Sometimes us tennis players, we struggle to forget. But that's the number one thing I've got to do right now."

Djokovic earned only 11 winners in the match, compared to Raonic's 42, but it was still enough to advance and keep him on track to win a record-tying sixth title at the year-end championship.

"All in all, two tiebreaks against a big server is a great win and great confidence boost," Djokovic said.

In the early match, Thiem went through another second-set letdown before putting things right to give himself a chance to advance.

The eighth-seeded Austrian, who is making his debut at the season-ending tournament, held on to beat Gael Monfils 6-3, 1-6, 6-4, making him 1-1 in the round robin.

In his opening match on Sunday, Thiem lost to Djokovic after winning the first set. In the second set of that match, he was blanked 6-0.

"I tried to avoid the mistake I did in the first match, to drop a little bit. Didn't really happen that good," Thiem said. "But I was trying to stay tough in the third set."

He got some help this time, though.

Although Monfils improved in the second set, winning all three of his break points to force a decider, his service game never really got going. In the final game of the match, the Frenchman gave it away with three of his five double-faults.

"It was a tough one," said Monfils, who is still recovering from a rib injury that forced him out of the Paris Masters at the end of last month. "I think I didn't play a great match, but I gave everything I had."

Because of his injury, Monfils said he may pull out of his final match against Djokovic.