One Al-Shabaab militant was killed and another one arrested in the Sunday night rescue in Alibule, 70km from Afmadow.
“They are safe in our hands, they have been freed,” said Kenyan army spokesman Cyrus Oguna.
“They were released in a joint force of Somali and Kenyan forces, during which one of the kidnappers was killed.”
The four aid workers, employed by the Norwegian Refugee Council (NRC), come from Canada, Norway, a dual national from Canada and Pakistan, and the Philippines.
One has a bullet wound to the leg but they are otherwise unharmed.
“They are exhausted, they have walked far and have blisters, and one of the aid workers was shot in the leg, but otherwise they are in good health,” Oguna said, adding they were now in the southern Somali border town of Dhobley.
“They are receiving medical attention at our base while they await transfer back to Kenya,” Oguna added.
Mohamed Dini Adan, the Somali military commander in Dhobley, said the army had stopped the “kidnappers who were trying to hide and sneak past the army.”
Somali commanders also confirmed the hostages, seized on Friday in the Dadaab refugee camp, had been released.
Military helicopters and police had chased the gunmen on Friday, who drove off with the hostages in their vehicle. It was later found abandoned, with fears the gang were heading towards Somalia, some 100 kilometres (60 miles) from Dadaab.
NRC is working to support some 465,000 inhabitants in the Dadaab complex, which constitutes Kenya’s third-biggest town in size of population.