South Korean presidential spokesman Cheon Ho-sun said from Seoul that the deal had been reached "on the condition that South Korea withdraws troops by the end of year and South Korea suspends missionary work in Afghanistan," he said.
Seoul has already said it planned to withdraw its troops by the end of the year. Some 200 South Korean soldiers have been deployed in Afghanistan for reconstruction efforts, not combat.
South Korean missionaries have been active in Afghanistan, but travel to the country independently. The government has insisted that the 19 kidnapped South Koreans were not missionaries, but were doing aid work.
There was no word on when the captives would be released.
The Taliban had also been demanding the release of militant prisoners in exchange for the captives' freedom. Afghan officials had ruled out any exchange, saying such a move will only encourage further kidnappings.
The Taliban kidnapped 23 South Koreans as they traveled by bus from Kabul to the former Taliban stronghold of Kandahar on July 19. In late July, the militants executed two male hostages. They released two women earlier this month as a good will gesture.
Tuesday's agreement came after face-to-face talks between both sides in the central town of Ghazni. It was the fourth time the two sides had held direct negotiations. All the talks had been mediated by representatives of the International Committee of the Red Cross.
Abductions have become a key insurgent tactic in recent months in trying to destabilize the country, targeting both Afghan officials and foreigners helping with reconstruction. A German engineer and four Afghan colleagues kidnapped a day before the South Koreans are still being held.