The president’s most surprising ally was a pariah in his first term.