The five-time champion was also taken the distance in his opening-round victory over American teenager Frances Tiafoe earlier this week, and he again survived a scare to battle through 6-1 (3)6-7 4-6 6-4 6-1 at Flushing Meadows.
The 36-year-old, who has won the two Grand Slams he has entered so far this year, wasted no time in taking control of the first set as he raced into a 5-0 lead with two early breaks before wrapping it up with his third set point.
Federer looked to be on course for a commanding two-set lead when he broke Youzhny twice more in the second set on his way into a 4-2 lead, but this time the world number 101 fought back to force a tie-break, which he went on to win 7-3.
Federer - chasing a record sixth US Open and 20th Grand Slam title overall - then found himself behind when a solitary break in the third set allowed Youzhny to take it 6-4.
The world number three quickly responded by moving into a 4-1 lead in the fourth and, while Youzhny delayed matters by denying Federer when the Swiss was serving for the set, the Russian lost on his own serve in the very next game as Federer took it 6-4.
Cramp affected the 35-year-old at the start of the deciding set, and Federer took full advantage to win four games in a row on his way to a 6-2 triumph.
Federer will now face Feliciano Lopez for a place in the last 16.