The Probhati Express with many passengers riding atop the carriages was bound for the capital, Dhaka, from the port city of Chittagong, 135 miles to the southeast, when five of the rear cars went off the rails.
Bangladesh Railway spokesman Shafiqul Alam said three bodies had been found and at least 100 people were injured. Those hurt were taken to nearby hospitals, where two others later died of their injuries, Alam said.
Rescuers were still searching for more possible casualties, he said.
"I don't know what happened. The car suddenly fell off the track and landed on its side," said Sohrab Hossain, a rooftop passenger who was hospitalized with a fractured hip and wrist.
The train was packed with about 1,000 people returning home for the three-day Muslim Eid al-Fitr holiday, which marks the end of the fasting month of Ramadan.
It was not immediately clear what caused the derailment. Investigators were on their way to the site about 25 miles north of Chittagong, Alam said.
Accidents including collisions or derailments are common on Bangladesh's aging railway system. In June, a train collided with a bus that ignored a stop signal at a crossing in northern Tangail town, killing at least four people and injuring 30 others.