"They are safe in our hands, they have been freed," Kenyan army spokesman Cyrus Oguna told AFP, adding that the two men and two women seized on Friday were freed after a combined operation of Kenyan and Somali troops.
"They were released by a joint force of Somali and Kenyan forces, during which one of the kidnappers was killed," he said. Three others were arrested.
The aid workers with the Norwegian Refugee Council (NRC) come from Canada, Norway and the Philippines, the fourth being a dual national from Canada and Pakistan. NRC said in a statement it was "relieved and pleased" at their release.
One has a bullet wound to the leg but they are otherwise unharmed. They were due to be flown to the Kenyan capital later Monday from Dhobley, a southern Somali border town under control of Somali forces allied to Kenya.
"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.
"They are receiving medical attention at our base while they await transfer back to Kenya."
Mohamed Dini Adan, a Somali military commander in Dhobley, said the army had stopped the "kidnappers who were trying to hide and sneak past the army."
Somali forces heard reports the gunmen were heading for a dense remote forest some 25 kilometres (15 miles) from Dhobley, and rushed to hunt them down.
"Thanks to God we foiled their aims of taking the hostages into the forest," said Somali General Osmail Sahardid, who led the operation.
Residents in Dhobley said the local Ras Kamboni militia -- commanded by a former powerful Islamist warlord now allied to Kenya -- were also involved in the rescue.
Kenyan security forces scrambled military helicopters and aircraft after gunmen attacked the NRC convoy at around midday Friday in Dadaab, some 100 kilometres (60 miles) from Somalia, killing a Kenyan driver and wounding two others.
However, the aid workers' vehicle seized by the gunmen was found abandoned a few hours after the attack, and fears grew the gang had escaped with the hostages through the remote scrubland across the porous border into lawless Somalia.
Kenya, which invaded southern Somalia in October to attack Al-Qaeda linked Shebab insurgents, has troops some 120 kilometres (75 miles) deep into Somalia. However, the forces control only pockets of the vast territory.
The kidnapping was the latest in a series of attacks in Dadaab, where gunmen last October seized two Spaniards working for Medecins sans Frontieres (Doctors Without Borders). They are still being held hostage in Somalia.
The abduction of the Spaniards was one of the incidents that spurred Kenya to send troops and tanks into Somalia to fight the hardline Shebab who Nairobi blames for abductions and for cross-border raids.
On Sunday, gunmen killed 17 people in the worst attack since Kenya invaded Somalia, with masked insurgents hurling grenades into two churches in the eastern garrison town of Garissa before firing guns into the congregation.
The pro-Shebab Twitter site Al-Kataib boasted of a "successful operation in Garissa" but did not specifically claim responsibility.
The Shebab still control large parts of southern Somalia, despite recent losses to African Union troops, government forces and Ethiopian soldiers, who have wrested several key bases from the insurgents.