BERLIN — The populist, pro-Russian president of the Czech Republic fended off a vigorous challenge from a pro-E.U. political neophyte Saturday in an election widely seen as a referendum on whether the central European nation will tilt East or West.

The narrow victory delivered a second five-year term to Milos Zeman, the wily 73-year-old political veteran who is known for his inflammatory rhetoric, his close ties to Moscow and his self-described image as “the Czech Trump.”

“This, my dear, is my last political victory, and no loss will follow it,” a beaming Zeman told cheering supporters as he vowed to abide by a constitutional two-term limit.

The result marked a major defeat for pro-Western forces in the country, which had mobilized behind Jiri Drahos, a 68-year-old chemist. The low-key former head of the Czech Academy of Sciences had campaigned on a platform of robust support for the European Union and a more civil approach to politics.

In a speech to hundreds of deflated backers, Drahos congratulated the incumbent and said the ideals behind his campaign would live on.

“I am thankful for the enormous wave of energy that has surged with this election,” he said, an arm draped around his wife’s shoulder. “This energy cannot disappear. And I am convinced that it will not disappear.”

Polls going into the election had shown a dead-even race. But the final tally gave Zeman a 51- to 49-percent edge, with about 66 percent of voters casting ballots in the nation of 10.5 million.

In the campaign’s final days, Drahos had been hit by a barrage of online attacks, with websites, chain emails and social media posts spreading misinformation. The campaigns variously alleged that Drahos was behind a secret globalist society, had hidden plans to open the country to mass immigration and is a pedophile.

Drahos had spoken out against the assault before the vote, saying it was “logical” to think that Russia was trying to interfere in the campaign.

He did not directly address the issue Saturday, saying his campaign would wait to analyze the results.

The Czech president does not run the government; that job is carried out by the prime minister. But the presidency is an influential institution, one that sets the political tone for the country.

The president has the power to veto laws and appoint a prime minister, a particularly important role now given that the country has been locked in political paralysis since October parliamentary elections.

That vote ended with the party of billionaire populist Andrej Babis coming out on top but needing partners to form a government.

So far, he has been unable to find them, with other parties saying they will not support Babis as prime minister while he is under investigation for alleged fraud.

Zeman’s victory will be a boost for Babis, a close ally. Babis had endorsed Zeman in the presidential campaign, while Zeman has said he will continue to support the businessman’s attempts to form a government.

With Babis and Zeman in charge, Czech advocates for closer integration of the country with its Western allies fear there could be a shift the other way. Both Hungary and Poland have bucked the E.U. in recent years, while moving in a more populist and authoritarian direction. The Czech Republic has been more cautious, but shares Hungarian and Polish resentment toward E.U. directives to take in refugees.

Although the Czech Republic has accepted just 12 of the 2,600 asylum seekers it was supposed to take, the president capitalized on the issue.

Zeman has long seemed to delight in provoking outrage. He has said Muslims are “impossible” to integrate in Europe and that E.U. leaders are “cowards.”