Kyrgios was not able to recover and surrendered the first set in a marathon tiebreak where he finally succumbed to the pressure 11-9.
Kyrgios was booed by the crowd as he went to rest in his seat during the break between sets.
From then on, he was hunted by the pumped-up crowd.
The chair umpire at one point late in the first set had to remind the crowd to "please show good sportsmanship to both players" after a Kyrgios double-fault attracted huge applause from the heavily-Federer-favouring Miami locals.
Immediately after the warning, a spectator again yelled out while Kyrgios was preparing to serve, forcing the Australian to blow up at the offender, telling the crowd to "shut up".
The pair continued to deliver an elite level of tennis, regularly bringing the crowd to their feet, but Kyrgios was forced to fight jeers all the way through the tense second set.
When the 21-year-old forced a delay in the game by walking over to his seat to change racquets, the crowd again let him have it with a volley of heckling with the match on serve at 2-1 in the second set.
While the crowd could be heard going after Kyrgios, broadcast cameras filmed Ferderer's wife Mirka joining in on the fun in a hugely controversial moment of the match.
Kyrgios and Federer continued to hold serve throughout the second set, forcing the pair into another tiebreaker.
Federer grabbed an early mini-break and had a chance to serve out the set with two serves at 5-4 before Kyrgios hit a booming down-the-line winner.
Kyrgios also had a set-point at 7-6 in the tiebreak but could only watch as Federer produced a first-serve one-two punch with an easy mind-court put-away.
Kyrgios finally seized his moment to go 11-9 up after another marathon breaker to level the match at a set all.
The two players continued to reach deep into their bag of tricks in the decider, which headed into a third tiebreak.
The enthralling contest reached a new level of drama when Federer, in the middle of the rally, pulled up and challenged a deep approach shot from Kyrgios that was judged in by the linesman at 2-3 down in the tiebreak.
The Hawkeye replays showed Kyrgios' approach sailed just long, levelling the breaker at 3-3 at the change of ends.
Kyrgios grabbed a mini-break at 5-4 and had two serves to take out the contest.
On the first point Kyrgios became agitated when a fan yelled out just as he was about to hit a deep forehand.
The Canberra product appeared to lose his cool after watching his shot sail wide and long.
In a fit of rage he turned his back to Federer and screamed abuse at spectators at the back of the court.
"Oh my god, shut up," Kyrgios reportedly yelled at fans.
"Shut the f*** up. What the f*** are you doing?"
From that moment on the match was Federer's.
He grabbed back the lead two points later and then served out the match with a first serve down the tee that Kyrgios was unable to return.
Federer's 7-5 tiebreak win sealed a famous victory.
The Aussie blew up and smashed his racquet at the moment of his defeat as the crowd exploded with cheers when he couldn't return Federer's serve.
Federer will now play old rival Rafael Nadal in the final after the Spaniard raced through a routine 6-1 7-5 victory over Fabio Fognini in the earlier semi-final.