Just three days after a visit to Moscow that infuriated his European allies, Prime Minister Viktor Orban of Hungary sprung another surprise on Monday by turning up in Beijing for previously unannounced talks with China’s leader, Xi Jinping, that featured promises to strengthen their countries’ robust relationship.

The visit to China, planned in secret like his trip on Friday to Moscow to meet President Vladimir V. Putin, is likely to intensify criticism in the European Union that the Hungarian leader is courting authoritarian leaders in defiance of the bloc’s stated foreign policy goals.

In May, Mr. Orban had given Mr. Xi a red-carpet welcome in Budapest, the Hungarian capital, bolstering China’s efforts to restore its influence in Europe at a time when the European Union as a whole is trying to contain the reach of a country it views as a “systemic rival.”

China’s official summary of their meeting on Monday in Beijing said they discussed their ideas to end the war in Ukraine, where both governments favor terms that Ukraine rejects as tilted toward Russia.

This meeting gave Mr. Xi and Mr. Orban, an outlier in the European Union on support for Ukraine and other issues, a chance to press the bloc to distance itself from Washington, with which Hungary also has strained relations. Hungary began its six-month rotating presidency of the Council of the European Union this month, giving Mr. Orban a higher profile, though not much more influence, in European affairs. Still, Mr. Xi seemed to ask Mr. Orban to do what he could.

Mr. Orban has for years worked to curb criticism of China by the European Union, upsetting countries that support Washington’s hawkish position on the need to counter what they see as unfair Chinese trade practices.