At least 41 people were killed and more than 130 injured when two trains collided in the Egyptian city of Alexandria on Friday. Footage of the crash site showed medics working to rescue the injured from the wreckage.
The prosecutor has ordered the detention of two train drivers and their assistants involved in Friday's fatal accident, according to the state news agency MENA.
The engineers are to be held for 15 days while the investigation continues. Blood and urine samples were taken from one driver to test for drug use.
Transport Minister Hesham Arafat told President Abdel-Fattah el-Sissi that the accident was the result of human error, though he did not elaborate.
Egyptians have long complained that successive governments have failed to maintain basic safeguards on the railway lines, and Friday's accident was just the latest in a series of crashes that have heightened public anger.
The Egyptian Railways Authority said that a train traveling from Cairo hit a train waiting Friday at a small station in the district of Khorshid, at about 2:15 p.m. local time. The idle train had recently arrived from the Mediterranean city of Port Said.
It did not say what caused the accident, but said that experts would investigate. Transport ministry officials separately told state television that the crash could have been caused by a malfunction in one of the trains that caused it to stop on the tracks.
A local resident only identified as Hoda told the Reuters news agency that she was standing on her rooftop when she saw the trains plough into each other.
"They rose in the air forming a pyramid when they collided," she said. "I started to scream from the rooftops for people to grab some sheets and run."
Images of the crash site broadcast on state television showed that several carriages had derailed as a result of the collision and that one train had partly keeled over. The footage also showed bodies covered with bed sheets lying near the tracks while medics worked to move the dead and injured to ambulances. Locals also rushed to the tracks to help the crash victims.
Passenger Moumen Youssef said: "The train I was riding was going very quickly. I found myself on the floor. When we came out, we found four train cars crushed and a lot of people on the ground."
The Health Ministry released a statement saying 42 people were killed and 133 were injured.
President Abdel Fattah al-Sisi and the country's chief prosecutor, Nabil Sadeq, both ordered an inquiry into the crash.
Deadliest crash since 2013
Friday's crash was the deadliest train accident in the North African country since a November 2013 crash between a bus and a train that killed 27 people south of Cairo.
Egypt's worst rail disaster took place in 2002 when a train traveling to southern Egypt caught fire, killing over 360 people.
The country's railway system has a poor safety recordthat has been blamed on poor management and badly maintained equipment.