Poland on Sunday elected nationalist Karol Nawrocki, who has been critical of Germany, as president.