CAIRO — A train slammed into a barrier at Cairo’s main railway station and exploded on Wednesday, sparking a major fire that killed at least 20 people and injured 40.

Hours later, Transportation Minister Hisham Arafat resigned, according to a cabinet statement.

The National Railway Authority said in a statement that the blaze erupted after the train struck a concrete barrier at Ramses Station, in central Cairo. The train’s fuel tank apparently exploded, creating a huge ball of flames that engulfed the platforms and nearby buildings.

Egypt’s prosecutor general said Wednesday evening that a preliminary investigation indicated that a fight between two train conductors caused the crash.

The conductor of the train that crashed had stepped off it, without applying the hand brake, to confront a conductor who was blocking the way with his rail car, Nabil Sadek said in a statement.

“The driver left the rail car without taking any measures to put on the brakes,” Sadek said.

Images on Egyptian television and social media showed heavy plumes of black smoke rising from the station as ambulances and fire engines arrived.

Surveillance-camera videos that later circulated on social media revealed the chaos inside the station. One video showed a massive ball of flames engulfing a platform as passengers fled. A man covered in flames is seen stumbling as other passengers try to douse him with water.

“Suddenly everything turned orange,” said Hend Ahmad el-Taher, 30, a teacher, who was in a cafeteria waiting for her train to depart when the explosion occurred. “People in flames were running and screaming.”

Egypt’s railway infrastructure has long been neglected, and previous train accidents have been blamed on a lack of investment and poor management of the railway network. Arafat had recently asked President Abdel Fatah al-Sissi for more money to rebuild the rail infrastructure.

The Wednesday explosion and the minister’s resignation are likely to renew questions about Sissi’s economic priorities. He has spent billions on major projects, including building a new capital and bolstering the military. But the government has focused little on refurbishing ­dilapidated infrastructure or spending on public education and health care in a country where 90 percent of the population lives in poverty.

Train accidents are alarmingly common in Egypt and have been increasing. In 2017 alone, 1,793 such accidents occurred, according to government statistics. In 2011, in comparison, there were 489 ­accidents.

In August 2017, 43 people were killed when two passenger trains collided near the northern coastal city of Alexandria. And in 2002, a fire swept through an overcrowded train near Cairo, killing more than 370 people. It was the nation’s deadliest train accident.

On Wednesday, most of those killed were on the platform, waiting for their trains or heading toward the exit.

“I ordered my coffee and was about to pay for it and get back to my train,” Taher recalled. “But God worked His ways and the guy at the cafeteria took too long to get my coffee. In just one second, what happened happened. I could have been out on the platform.

“It was a nightmare,” she added. “Even the people who got out safe were terrified.”