Inside are the luxuries of first-class rail travel, including flat-screen televisions and refrigerators in the sleeper cabins. Rowdy young army recruits, answering the call to arms from their Shiite religious leaders and on their way to basic training, crowd the brightly lit cafe car. The food is second-rate — cold fried chicken and soggy French fries — but there is a good falafel joint in Hilla, a town on the way; if you call in advance, sandwiches will be waiting at the station.

The new train is a small but noticeable sign of progress — of oil money spent in the interests of the public — in a country consumed by violence and corruption that is quickly coming apart in the face of an onslaught by the Sunni militants of the Islamic State, also called ISIS or ISIL.

It is also a reminder of what has been lost in Iraq and in the broader Middle East. Once, the region was connected by trains; building rail lines was central to the imperial ambitions of European powers — the Germans, the British and the French — to exert influence in the Middle East in the years before World War I, when the region was part of the Ottoman Empire. In more recent times, sectarian violence has torn apart diverse societies, especially in Iraq and Syria, that, for better or worse, were once held together by dictators. The areas reachable by trains have steadily shrunk, the diversity of the passengers who rode them a long-lost memory.

“Before was different,” said Ahmed Ali, who for 31 years has held various jobs for Iraqi Republic Railways, the state rail authority, and now works as a cashier in the cafe car. “I used to meet the educated people, the uneducated, the actors, the poets, the poor man. Many different groups.”

He adds, “Now, everything is gone.”

Mr. Ali recalled trips to Mosul, where on layovers he would visit the city’s famous tombs and shrines, and buy candy and pistachios and clothes to bring back to his family in Baghdad. For months now, Mosul, Iraq’s second-largest city, has been under control of the militants, and many of those historical sites have been destroyed.