BEIJING, OCT. 20 -- South Korea and China, which long has supported Communist North Korea, agreed today to set up trade offices in each other's capitals, the first official step toward improved relations between the former enemies.

The move came just three weeks after the Soviet Union, another major ally of Pyongyang, established formal relations with Seoul, and it underscored a changing political climate that could facilitate an easing of tensions between the two Koreas. It also marked a new foreign policy step for China, still trying to break out of the diplomatic isolation that resulted from the Chinese army's crushing of a democracy movement in June 1989.

After more than 18 months of negotiations, the chairman of the China Chamber of International Commerce, Zheng Hongye, and the president of the Korea Trade Promotion Corporation, Lee Sun Ki, signed an agreement today to promote trade and economic and technological cooperation between the two countries. The agreement becomes effective immediately, and South Korean officials hope to set up offices by the end of the year.

South Korean officials have said the offices could serve as channels for official contacts and help pave the way for establishment of diplomatic relations. "It makes things look brighter over the long term for eventual normalization of ties," said one Western diplomat.

China, a major ally of North Korea, joined forces with Pyongyang to fight South Korean and U.S.-led United Nations forces in the 1950-53 Korean War. Seoul and Pyongyang have been bitter enemies since then.

Although Beijing recognizes only North Korea, it has in recent years cautiously wooed trade from Seoul in an effort to bolster its economy and unofficial trade has grown enormously in the past few years, reaching $3.2 billion last year. By contrast, Beijing's trade with North Korea is estimated to be only $400 million to $500 million a year.

China and South Korea are now each other's seventh-largest trading partners. China offers South Korea foodstuffs, coal and other raw materials, while seeking investment, technology and manufactured goods.

While Chinese officials say there will be no change in their policy toward South Korea despite the agreement to open trade offices, recent political developments on the Korean peninsula may give Beijing more flexibility to pursue official ties, one diplomat said.

Since the fall of communism in Eastern Europe, all of the countries in that region have established relations with Seoul, and three weeks ago, the Soviet Union took the same step. Two days before the Soviet announcement, in another major policy shift, North Korea called for negotiations to restore normal diplomatic relations with Japan, which recognizes South Korea.

Details of the agreement signed today were not available. The brief official New China News Agency dispatch did not say when the offices would be established or whether they would have consular functions. But in Seoul, a spokesman for the state-run Korea Trade Promotion Corp. was quoted as saying the offices would have limited consular functions.

China and South Korea were planning to set up trade offices in each other's capitals earlier, but talks were halted after the 1989 Chinese army crackdown on demonstrators for democracy, diplomats said.

There has been more recent cooperation between the countries. South Koreans were major contributors to the recently concluded Asian Games, which Beijing hosted. Apart from about $15 million in revenue from commercial billboards rented by South Korean companies, Hyundai and other automobile makers donated 400 cars to help transport athletes and officials during the games.

The rapprochement between Beijing and Seoul reportedly prompted a secret visit to China last month by North Korean leader Kim Il Sung.