SEOUL, South Korea — South Korea elected Moon Jae-in, a human rights lawyer who favors dialogue with North Korea, as president on Tuesday, returning the nation’s liberals to power after nearly a decade in the political wilderness and setting up a potential rift with the United States over the North’s nuclear weapons program.