Suspected Boko Haram militants launched an attack on the prison in the southern Niger town of Diffa late on Saturday, military sources said, in an apparent bid to free fellow members of the Nigerian Islamist group held there.
Three of the assailants and one soldier were killed before the attack was repelled, the sources said. Boko Haram also attacked the prison in February.
"When the attack was repelled, the assailants fled, probably back into the town," one military source said. "We are searching for them."
A second military source said the attackers may have been residents of Diffa, as no one had seen them enter the town.
Boko Haram is seeking to carve out an Islamic state in northeast Nigeria. Despite losing territory to an offensive by regional militaries this year, Boko Haram has carried out a wave of deadly attacks in Nigeria, Chad and Niger in recent weeks.
The group has sworn allegiance to Islamic State, which has declared an Islamic caliphate in the large parts of Iraq and Syria that it controls.