The 17-time Grand Slam winner, and 17th seed at the Australian Open, dropped the second set to Melzer but came back strongly.
The 35-year-old Swiss had to battle hard throughout the two-hour, six minute contest and only really eased clear of his dogged opponent when the Austrian tired in the final set.
Federer could be forgiven a little rustiness after his prolonged absence to nurse a knee injury and made 36 unforced errors but there were also plenty of reminders of the brilliant skills that have won him 17 Grand Slam titles, four at Melbourne Park.
Seeded 17th, Federer has much tougher battles ahead if he makes it through to the second week of the tournament but will next pit his skills against American qualifier Noah Rubin.
"It's nice to be playing normal tennis again, on a centre court like this, it's beautiful and I couldn't be happier out here now," said Federer.
Highlights: Federer comes through in four against Melzer
"It's been a long road and I made it. I'm in the draw which is a beautiful thing. I hope I can stick around a bit."
"Any match is a good match. Even if I would had lost today it would be a good because I am back on the court."