Taleban militants say they have agreed to free 19 South Koreans held hostage for more than a month in Afghanistan.

Seoul said the agreement was reached on condition its troops were withdrawn as scheduled by the year's end.

South Korea also agreed to end all missionary work in Afghanistan and stop its citizens from travelling there.

The rebels kidnapped 23 Christian charity workers from Ghazni province on 19 July. They subsequently killed two male hostages, and freed two women.

The BBC's Alastair Leithead, in Kabul, says no exact release date has been given, but the Taleban have said they will start working straight away to free them.

There has been no mention of money being paid, our correspondent adds, but it is thought that a ransom may have been part of the deal.

A Taleban representative, an official from the South Korean government and mediators issued a statement in Ghazni - where the 19 are being held - saying that they had come to an agreement and the hostages would be released as soon as possible.

Koreans rejoice

The announcement was greeted with celebrations in South Korea, where families have been waiting anxiously for news of their loved ones.

Cho Myung-ho, whose 28-year-old daughter Lee Joo-yeon is being held hostage, told the Associated Press: "I would like to dance."

Kim Kyung-ja (left) and Kim Ji-na were freed earlier this month

The Christian church that the hostages belonged to, near Seoul, said all the families were "rejoicing".

"They are busy calling other family members and friends at the moment to pass the news," Bang Yong-kyun, pastor at the Saemmul Church, told Reuters.

Tuesday's agreement came after South Korean negotiators met Taleban representatives in the central town of Ghazni.

Tribal elders and two diplomats from the Indonesian embassy in Kabul also took part in the talks.

Withdrawal plan

It was the fourth time the two sides had held direct negotiations - all of the meetings being mediated by members of the International Committee of the Red Cross.

But it was the first time the sides had met since two of the female hostages were freed two weeks ago.

The South Koreans were seized in Ghazni province as they travelled by bus along the main Kandahar to Kabul highway.

In late July, the Taleban murdered two of the male hostages - the group's pastor, 42-year-old Bae Hyung-kyu, and former IT worker Shim Sung-min, 29.

Seoul had already said it planned to withdraw its troops by the end of the year.

Some 200 South Korean non-combat personnel are deployed in the country to help with reconstruction efforts.