At his post-match interview, he said: "It's the a year ago of professional tennis for me. Winning these type of matches against a top 10 player like "Sascha" is a gift", he said.
However, the Swiss star responded quickly by breaking back and he broke Krajinovic again to win the first set 7-5.
Federer, a three-time champion of the ATP 1000 event, scraped past Albot 4-6 7-5 6-3 after two hours, nine minutes.
Albot came out of the blocks firing and immediately put Federer under pressure, fashioning two break points in the opening game.
Three-times Miami champion Federer finished with 38 winners but had to overcome 41 unforced errors to defeat Albot.
Federer will next face Serbia's Filip Krajinovic on Monday.
It was Anderson's first tournament appearance since the Australian Open in January and he said he was happy with the way his elbow felt.
"It was more humid today so I am just delighted to get through". "I feel like I'm hitting the ball great", the sixth seed added.
Federer, however, stylishly weathered the storm to seal the win - the 52nd of his career in Miami - to move into the quarter-finals and a match with either American Reilly Opelka or Daniil Medvedev.
Eighth seed Stefanos Tsitsipas easily beat Mackenzie McDonald 7-6 (4) 6-1. That break off serve aided the Moldavian to dominate the first set and later he went on to seal the set 6-4.