Germany has elected a new leader in an election that saw the far-right secure an unprecedented surge, while the Social Democrats suffered their worst result since WWII.