Hungary's prime minister has been ousted after 16 years in power, with Péter Magyar set to be the country's new leader.