From 1942 to 1945, Hayes served as US ambassador to Spain. He was attacked at the time from the left for being overly friendly with Francisco Franco, but it has been generally held that he played a vital role in preventing Spain from siding with the Axis powers during the war. Historian Andrew N. Buchanan posits that Hayes made Spain into "Washington's 'silent ally.'" In 1945 President Roosevelt wrote him saying: "You have carried out a mission of great difficulty with outstanding success and in doing so you have made a contribution to the war effort of the highest importance".