TOKYO, OCT. 11 -- It wasn't until about 7 this morning, when an all-night haggling session finally drew to a close, that North Korean negotiators agreed to take a small but crucial step toward ending their nation's isolation from the capitalist world.

The North Koreans had declared themselves willing to release two Japanese sailors imprisoned for seven years on spy charges. But they insisted that to secure the seamen's freedom, the Japanese government would first have to guarantee that the pair would never say or do anything to harm the budding relationship between Tokyo and Pyongyang.

In the end, the North Koreans freed the sailors, acceding to the Japanese negotiators' explanations that proscribing the seamen's free speech would violate Japan's constitution.

The freeing of the pair, whose fate has been extensively covered by the Japanese media, was hailed by Tokyo as removing the most significant obstacle to initiating the process of establishing normal ties with North Korea. The Pyongyang regime is one of the world's last hard-line Communist states, but it has recently indicated an interest in joining the global thawing of the Cold War, making its first overtures to Japan.

The two sailors arrived here shortly before noon on a chartered All Nippon Airways jet, accompanied by several Japanese politicians. Before being whisked off to a hospital for medical examinations, they were greeted on the plane by their wives, who reportedly shook their husbands' hands and patted them on the back.

"We were both very moved," one of the wives, Tamiko Kuriura, 55, said later at a news conference, adding that upon being reunited she and her husband had been so overwhelmed by emotion that neither could speak.

Kuriura's husband, Yoshio, 59, and Isamu Beniko, 60, were the first mate and captain, respectively, of the Fujisan Maru No. 18 when they were arrested in November 1983 during their ship's stop at a North Korean port. They had allegedly helped a North Korean soldier escape to Japan by allowing him to stow away on their vessel on an earlier trip.

Their release became possible when Tokyo and Pyongyang began making moves in recent weeks toward ending the bitterness that has characterized their relations since World War II. A former Japanese deputy prime minister, Shin Kanemaru, secured a commitment to free the seamen when he visited the North Korean capital last month.

Like other Communist countries, North Korea is enduring economic hardship, and it sees Japan as a rich potential source of aid. Today's development paves the way for governmental negotiations over a host of issues, including war reparations and the establishment of travel between the two countries.

Yet the last-minute argument over the terms of the sailors' release suggests that the road to normal ties may not be smooth. The North Koreans allowed Beniko and Kuriura to go free only after the Japanese agreed to sign a letter stating that they would make their "best efforts" to keep the seamen from making statements injurious to relations between the two countries.

The sailors' return to Japan was an especially happy occasion for Min Hong Gu, the 27-year-old former North Korean soldier who had stowed away on their ship. According to the Kyodo news service, he said he wanted to apologize to the seamen for having caused them so much trouble, adding: "I would like to do anything in my capability; I could give them my kidney."