China says it will allow a group of North Korean asylum seekers in Seoul's diplomatic missions to leave the country, ending a month-long diplomatic standoff.

Beijing announced Sunday that the North Koreans will be allowed to leave for a third country, provided they have not committed a crime in China.

South Korean officials confirmed the 21 North Koreans in Seoul's consular offices in Beijing would be allowed to leave, as well as two women in the South Korean Embassy and a North Korean man detained by the Chinese police.

The man in custody was detained after a violent scuffle between South Korean diplomats and Chinese police when he tried to enter the diplomatic mission.

The deal apparently came after South Korea said it accepted China's view that diplomatic offices should not be used by illegal immigrants seeking asylum in another country.

Beijing has been facing a dilemma over the asylum seekers. It signed a treaty with its communist ally, North Korea, to hand over any illegal immigrants. But the issue took on an international dimension when dozens of illegal North Koreans began seeking refuge in foreign diplomatic missions in China earlier this year.

Aid agencies say tens of thousands of North Koreans fleeing famine and repression have found their way into northern China, where many ethnic Koreans live.

Over the past few months, China had allowed 38 North Koreans who sought asylum in foreign diplomatic missions to leave for South Korea via a third country, usually the Philippines.

But Beijing took a tough stand when the North Koreans began seeking asylum in South Korea's consulate for the first time in May.