Berdych battled to force a decider and came from a break down in a third set to lead in the tie-break before 18-time grand-slam champion Federer rallied in Miami.

"I've had some tough losses here where I should have won, like against Tomas a few years ago and also against Nishikori, and they stay with you," Federer, who has won the ATP 1000 tournament twice, told ESPN.

"I'm happy to come have through.

"I definitely got very lucky at the end, but I think I showed great heart.

"I fought and Tomas definitely started to step it up, but it was a great match at the end."

Awaiting Federer in the semi-finals is 12th seed Nick Kyrgios, who was due to face the Australian Open champion at Indian Wells last week before withdrawing due to food poisoning.