A government official said the remote-control device was planted on the tracks near the town of Dera Murad Jamali in the district of Naseerabad in Baluchistan province.
Deputy district commissioner Sohail Rehman said five people were killed and 16 others injured.
The explosion also derailed four carriages.
Most of the passengers were returning to the provincial capital Quetta after celebrating holidays at home. There were three brothers among the dead.
Provincial government official Asad Gillani added: "The explosives had apparently been planted on the railway tracks as the explosion created a crater several feet deep."
No-one immediately claimed responsibility for the attack, but the province has been affected by a low-level insurgency by separatist groups, who want a larger share in the region's natural resources.
Al Qaeda-linked Sunni militants also operate there.