Dozens of soldiers held by villagers in a rebel-controlled area were released after UN and government mediation.