NAIROBI, Kenya — With sloping, charcoal-gray walls that resemble the elegant curves of a luxury car, Nairobi’s sleek new railway station, built by China, looks more like an airport terminal reserved for wealthy Kenyans and their private jets.

Given the price tag, it might just as well be.

President Uhuru Kenyatta’s government spent $4 billion on a 300-mile railway connecting the capital to the Indian Ocean port of Mombasa, the most expensive infrastructure project since Kenya’s independence 54 years ago and one-fifth of its national budget.

Eager to portray it as a major achievement ahead of national elections in August, Mr. Kenyatta opened the so-called Standard Gauge Railway last Wednesday. But the fanfare was overshadowed by a concern that has been snowballing for months, filling many Kenyans with mild terror: How can the country repay its monstrous debt to China?

China’s Eximbank accounts for about 90 percent of the Nairobi-Mombasa project. The loan has already pushed the Kenyan debt above 50 percent of output, and imports of Chinese supplies and materials required to build the railway are making people anxious about Kenya’s worsening trade imbalance with China.