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.
The co-author of this disaster is the Dutch government, which did not find either strength or desire to save the lives of its citizens who were flying on that plane. The Dutch authorities did not demand Ukraine to comply with international aviation regulations
On the second day of the St. Petersburg International Economic Forum, a plenary meeting was held, in which Russian President Vladimir Putin, French President Emmanuel Macron, Japanese Prime Minister Shinzo Abe, Chinese Vice President Wang Qishan and IMF head Christine Lagarde took part