LONDON (AP) — Kei Nishikori hit a backhand so good it threw Roger Federer off his game as the 20-time Grand Slam champion earned a code violation before capitulating in a surprise defeat at the ATP Finals on Sunday.

Two points away from losing the opening set and on the back foot in a rally, Nishikori hit a stunning shot up the line, which prompted Federer to hit the ball into the crowd and receive a warning for ball abuse.

Federer never appeared to regain his composure and went down 7-6 (4), 6-3 in a first opening match defeat at the season-ending tournament since 2013.

"I thought 'What was his argument, why the warning?" Federer said of his exchange with the umpire. "But nothing more than that. He thought I was angry. I wasn't. Now I'm angry because I lost, but I wasn't, so..."

Federer earned the first break points in the opening game of the second set, and took his chance, but Nishikori hit straight back in the following game.

Nishikori was the far more composed player from that moment on and broke for a 4-2 lead, before closing out the match for a first win over Federer since 2014.

"It's always a big challenge to play Roger," Nishikori said. "The first match is not easy."

Six-time champion Federer, who has reached the semifinals in all but one of his 15 previous appearances at the tournament, will now likely need to win his remaining two round-robin matches to keep alive his chances of claiming the 100th title of his career.

More thanks to poor returning than good serving, neither man was able to create so much as a sniff of a break of serve in an error-strewn opening set, until Nishikori's backhand denied Federer two set points with the score at 6-5, 15-30.

A tiebreaker followed and Federer made one of his 20 unforced errors in the set to give Nishikori the first mini-break and a 3-1 lead, which quickly became 6-1.

Federer rallied to save three set points, but Nishikori delivered a well-placed serve out wide to ensure the comeback attempt ended there.

However, his concentration deserted him moments later as a double fault gave Federer a break he did little to earn. But the Swiss responded in kind and a wild forehand error leveled the score at 1-1.

"Unfortunately I couldn't keep the lead that I got early (in the second set),"Federer said. "That was the key of the match, that sort of 10-minute swing at the end of the first through to maybe 1-1 in the second."

The seventh-seeded Nishikori began to relax and was rewarded in the sixth game as he brought up another break point and produced an inside-out forehand Federer had no chance of returning.

Despite having lost his last six meetings with Federer, including two on this court, Nishikori showed no nerves as he dropped just one point in his next two service games, with a forehand error from the Swiss great ending the match.

Earlier, Kevin Anderson made a confident start to his ATP Finals debut with a 6-3, 7-6 (10) victory over Dominic Thiem.

Having qualified for the tournament for the first time, the 32-year-old Anderson produced a dominant serving display to take the first set, before saving two set points to come through a tense tiebreaker in the second.

"I think it was important, you know, going out there and getting off to a good start," Anderson said. "I definitely felt a little bit nervous."

_

More AP Tennis: https://www.apnews.com/apf-Tennis and https://twitter.com/AP_Sports