Australia's Thanasi Kokkinakis has claimed the biggest scalp of his young career by beating Roger Federer at the Miami Open, a result that has cost the Swiss the world number one ranking.

The big-serving Kokkinakis, a qualifier ranked 175th, rallied to upset Federer 3-6, 6-3, 7-6 (7-4), with the 36-year-old Federer — the oldest number one in the history of the men's rankings — to lose top spot to Rafael Nadal.

Kokkinakis became the lowest-ranked male player to beat a world number one since Francisco Clavet, ranked 178, upset Lleyton Hewitt at the same Miami tournament in 2003.

"Pretty crazy," Kokkinakis said after the match.

"I'm pretty happy about it."

Federer was blunt in his assessment of how he performed against Kokkinakis.

"I deserve it after this match," Federer said.

"That's how I feel."

Federer has now lost back-to-back matches for the first time since 2014 — he went down to Juan Martín del Potro in the Indian Wells final last weekend.

It is a dip that comes after a career-best 17-0 start to the year.

The 6-foot-5 Kokkinakis has long been regarded as a promising talent thanks to a thunderous serve and forehand, but has been plagued by injuries. The match was his first against Federer, although they have practised together.

"I've always liked his game," Federer said.

"I'm happy for him that on the big stage he was able to show it. It's a big result for him in his career, and I hope it's going to launch him."

Federer's match turned when he played a poor service game and was broken at love to fall behind 3-1 in the second set.

"That game I knuckled down and put pressure on him," Kokkinakis said.

"I started to dictate from there."

Federer laments missed opportunities

Kokkinakis never broke again but held the rest of the way, consistently sending down massive serves.

"Every time I had chances, something bad happened," Federer said.

"Wrong decision-making by me, good decision-making by him. It's disappointing.

"I don't know why I couldn't get to any level I was happy with today."

Federer kept one exchange going by hitting a volley behind his back, but could not win even that point. He laughed then — it was early in the match — but looked grim two hours later as the end neared.

On match point, Federer buried a backhand return in the bottom of the net.

Kokkinakis screamed in celebration, waved his index finger and gestured for more noise from the appreciative capacity crowd.

Kokkinakis said he does not mind that fans were firmly in Federer's corner during the match.

"When I came on court there wasn't much cheering," Kokkinakis said with a laugh.

"He came on court with a little delay and that sort of strut he does, and I was like, 'This is pretty nuts.' The crowd goes nuts when he does his walk onto court."

The tournament is just Kokkinakis' fifth in the past seven months, but he said he thought he could beat Federer.

"When I'm playing on my terms, I don't feel there are too many people that can go with me," Kokkinakis said.

"I just needed to play my game and aggressive tennis."

Nadal will become the new number one even though he missed Miami because of a hip injury.

Kokkinakis was joined on the winners list by close friend and fellow Australian Nick Kyrgios, who defeated Dusan Lajovic 6-4, 6-1 to reach the third round.