Federer served for a straight-sets win in the third set and held two match points in the tie-break but Murray showed tenacity in the extreme to take the match into a fourth.
However, in only his seventh match after back surgery, he ran out of steam and Federer eventually clinched a 6-3 6-4 6-7 (6/8) 6-3 victory and a semi-final date with his old rival Rafael Nadal.
This was their 21st meeting and the first time Murray was the higher ranked.
But his lack of matches and Federer's form in defeating Jo-Wilfried Tsonga in the fourth round meant the Scot was hardly a clear favourite.
Murray drilled a clean winner off his backhand on the first point but soon Federer was pushing forward and making life hard for his opponent.
He brought up two break points in the fourth game and took the first when Murray fired a forehand long.
The fourth seed was playing well but Federer was in rare form, barely missing a first serve and hitting the ball as clean as a whistle off the ground.
Federer has a new bigger-headed racquet this season and a new man in his corner in Stefan Edberg, and both appear to have renewed his confidence.
Murray appeared confident in his game, too, and was certainly playing at a higher level than he had at any other time in the tournament.
The 26-year-old has consistently shown an ability to step it up against the top players, and this was a real step up after three players outside the top 100.
But two forehand errors in a row cost him in the fifth game as Federer broke to lead 3-2.
Murray was getting close to the Federer serve now but could not engineer a break point, and his frustration was evident as the second set slipped away.
The last time Murray had met Federer was in the semi-finals here last year, when he prevailed in five sets for his first win over the Swiss in a grand slam match.
He would have to go five again to repeat that, but that looked a remote possibility as he hung on grimly at the start of the third set.
Federer forced four break points in Murray's opening two service games but the fourth seed showed courage to save them all.
The Swiss still looked the better player, though, and he struck once more in the ninth game when Murray netted a forehand.
The British number one was unhappy that umpire Pascal Maria had allowed a Federer lob to stand even though it looked like the ball had bounced twice.
That left Federer serving for the match and for the first time he wobbled, three errors giving Murray his first two break points of the match.
He saved one but on the second a Murray backhand down the line drew the error and he was back to 5-5.
A tie-break would decide it, and it was a real nerve jangler for both men.
Federer looked like he had opened up a decisive lead at 5-2 and he had two match points at 6-4, but Murray played fine attacking points to save both.
The Scot then brought up a first set point and it was Federer who cracked, sending a forehand long.
Murray appeared to have the momentum and he opted to take a toilet break at the end of the set, giving Federer more time to reflect on his missed opportunities.
But it was Murray who had the mental letdown and found himself facing three break points in the second game of the fourth set.
He steeled himself to save those and then found himself embroiled in a 19-minute game, which he eventually extricated himself from after fighting off three more break points.
But that effort seemed to take its toll, with Murray dropping the speed on his first serve and beginning to look very weary.
He saved another break point to level at 3-3, but the pressure was growing, and when he slipped 0-40 behind at 3-4, Federer finally broke through.
Another twist seemed possible when the Swiss found himself 0-30 serving for the match for a second time, but he reeled off four points in a row, clinching victory with his 10th ace to move through to an 11th straight semi-final in Melbourne.