Historian came from behind to defeat centre-right rival Rafał Trzaskowski in win for Maga movement abroad