Federer, playing in his 18th Australian Open main draw, was the heavy favourite going in to the match, but Rubin pushed the four-time winner all the way in an engrossing tussle.
Aggressive from the off, Federer attempted to unsettle the 20-year-old qualifier. However, Rubin stood his ground, saving numerous break points in an entertaining first set. It looked as though the pair were heading for a tiebreak when Federer got the break he needed to take the opening set 7-5.
The second set followed a now-familiar pattern, with Federer attacking the Rubin serve. This time the American succumbed early, broken in the sixth game of the match to surrender the set.
The third was a much tighter affair.
Rubin broke at the start, and looked to be taking the match to a fourth set. However, Federer turned up the pressure while trailing 3-5 and managed to force the break.
With the set headed to a tiebreak, the momentum swung in the Swiss maestro’s favour, and he secured the set, and the match.
"He's a great fighter ... he's aggressive on the ball and I think he had the upper hand on the baseline," Federer said after the match. "I think my serving kept me in the match today ... I'm happy I got through somehow.
"I wasn't feeling as good (late) as in the beginning. I definitely got a little lucky in that third set ... so it was good to fight through."
In a re-match of the 2016 quarterfinal, Federer will face 10th seed Tomas Berdych in the third round.