KATHMANDU, Nepal — Xi Jinping touched down in Nepal on Saturday, the first visit by a Chinese president to the country in more than two decades, underscoring Beijing’s increasing interest in South Asia as a strategic hub for defense and transit projects.

Ahead of Mr. Xi’s two-day visit, which follows a trip to India, thousands of security officers took up posts around Kathmandu, Nepal’s capital. Workers planted flowers, repaired potholes and hung the Chinese president’s portrait on electricity poles.

Though Nepal has traditionally been close to India, in recent years, Chinese investors have pumped millions of dollars into the country, one of Asia’s poorest and least-developed democracies. And under Prime Minister K.P. Sharma Oli, leader of the Nepal Communist Party, Nepal has tried to diversify its trade agreements and move away from dependence on India.

Nepal, which borders Tibet and northern India, is the chief candidate for a new trans-boundary railway under China’s Belt and Road Initiative that would link China to the subcontinent.