PRAGUE — Czech President Miloš Zeman fought off a strong challenge from political novice Jiří Drahoš to win a second five-year term as head of state.

With virtually all of the votes counted, the 73-year-old Zeman had received 51.37% of the vote, against his challenger’s 48.62%. Turnout was just short of 67%. Zeman and Drahoš had topped a field of nine in the first round of the election, two weeks ago.

The result is likely to be viewed as bad news in Brussels, since Zeman has been in almost constant disagreement with the EU, notably regarding the migrant quotas and sanctions against Russia.

However, newly elected Czech Prime Minister Andrej Babiš will no doubt be celebrating along with Zeman. Since his election in October, Babiš has been struggling to form a viable minority government, having already failed once to receive a vote of confidence from the lower house of Parliament.

Most political parties have refused to support Babiš because he has been charged with defrauding the EU of a large subsidy for his Agrofert conglomerate. But Zeman has made it clear that he would give the prime minister as much time as he needs to put a stable government in place.

Drahoš is firmly pro-EU and has been very vocal about his opposition to having a man charged with a crime serving as head of the Czech government.

The campaign was marked by unpleasant attacks against the 68-year-old Drahoš, a physical chemist, with posts on social media accusing him falsely of pedophilia, cooperating with the former communist secret police and stealing some of the patents with which he is credited.

However, he was most damaged by being portrayed as a proponent of mass immigration, particularly through a broad billboard campaign carrying the message “Stop immigrants and Drahoš! This country is ours.” Around three quarters of Czechs are opposed to accepting migrants from Muslim-majority countries.

Drahoš has repeatedly said that he was against the EU-mandated quota program but that he was in favor of accepting a limited number of migrants.

After conceding defeat, he told supporters in Prague that he wanted to remain in politics, either by running for president again or for a seat in the senate.

"We will analyze the campaign, discuss what mistakes we made and what we should do better," Drahoš said. “We will continue.”

A visibly delighted Zeman told his supporters, tongue in cheek, that this was his last campaign. “This was my final political victory,” he said. “And after it, there will be no political defeats. Because, as you well know, according to the constitution the president can serve only two five-year terms, and I definitely do not want to change the constitution."

Zeman’s campaign faces accusations that it may have been partly funded by Moscow. Jakub Janda, deputy director of the European Values think tank, who has investigated the president’s links to Russia, says at least one-third of his campaign funding came from undeclared donors who used a shadowy NGO to hide the source of the cash. The president’s entourage has denied that Moscow played any part in the campaign.