British Prime Minister Margaret Thatcher and Chinese Premier Zhao Ziyang tonight formally signed the historic joint declaration that will return the crown colony of Hong Kong to Chinese sovereignty in 1997.

With China's paramount leader, Deng Xiaoping, looking on, Thatcher and Zhao sat at a green felt-covered table and signed the red velvet volumes of the accord in a 20-minute ceremony in the West Room of the Great Hall of the People.

More than 400 guests -- including more than 100 Hong Kong dignitaries and dozens of Chinese and British officials -- listened as Thatcher and Zhao reiterated each side's commitment to the agreement, paid tribute to the other side's efforts and, with obvious implications for the reunification of Taiwan with China, hailed the agreement as a model for resolving similar international situations.

The accord signals an end to nearly 150 years of British colonial rule over the world's third largest financial center and caps two years of tortuous negotiations between Peking and London. It pledges to guarantee Hong Kong's capitalism for 50 years after China recovers the territory from Britain on July 1, 1997, under a concept Peking calls "one country, two systems."

The 42-page document spells out Peking's plans to govern Hong Kong as an autonomous "special administrative region" and assures Hong Kong's 5.5 million residents that they will have basic freedoms unavailable to Chinese living on the mainland.

"We have accomplished a task of historical significance," said Zhao. "Our agreement provides fresh experience for the solution through peaceful negotiations of problems between nations that are left over from history."

In a lengthier speech, Thatcher first expressed her pleasure at Deng's presence and said: "The concept of 'one country, two systems' -- preserving the two different political, social and economic systems within one nation -- has no precedent. It offers an imaginative response to the special historical circumstances of Hong Kong. The concept is an example of how apparently intractable problems can, and should, be resolved."

Thatcher alluded to the difficulties in the negotiations, saying "there were moments of tension." But in closing, she turned toward Zhao and said: "I am heartened by the assurances which your government has repeatedly given that the arrangements for Hong Kong contained in the agreement are not measures of expediency."

As she finished speaking, waiters brought in champagne and, with glass in hand, Deng stepped forward to be the first to clink his glass with hers.

Although tonight's ceremony was a formality, the presence of Thatcher and of Deng -- who was not required to appear at a state ceremony -- underlined the importance that both sides attach to the document.

The Chinese preparation left nothing to chance. Minutes before the leaders were ushered into the room for the signing, Chinese attendants sprayed water on the carpet around the signing table to prevent the leaders from receiving static shocks during the obligatory handshakes.

For the Chinese, the accord symbolizes a resurgence of pride in regaining the 400-square-mile territory that Peking has maintained was ceded to the British under "unequal treaties" more than a century ago.

It also represents a personal triumph for Deng, who became personally involved as the negotiations entered their final stage and for whom the recovery of Hong Kong is another step in a larger goal of completing national reunification.

The Chinese, who are keenly aware that the implementation of the agreement will be closely watched by the world community, went to great efforts to repeat assurances that their policy toward Hong Kong will not change.

During 80 minutes of private talks with Thatcher before the 5:30 p.m. signing ceremony and banquet that followed, Deng reportedly also reiterated China's intention to abide by the agreement.

"I can tell you and the whole world, China will strictly abide by this agreement and honor its promise," a Chinese Foreign Ministry spokesman quoted Deng as saying. Deng, 80, also told Thatcher that he hoped he would still be "fit enough" in 1997 to go to Hong Kong "to have a look himself," the Foreign Ministry spokesman said.

Since the colony provides China with its largest source of foreign exchange -- between 25 to 40 percent -- as well as access to high-level technical and commercial expertise, there is a more immediate motive for Peking to leave Hong Kong unchanged.

The Communists could also cite the liberal accord as proof of their good intentions for incorporating the island of Taiwan and as a basis for opening negotiations with its reluctant Nationalist Chinese leaders.

The significance for Taiwan was not lost on the foreign guests. Deng's meeting with Thatcher took place in the Fujian Room of the Great Hall and the briefing for the foreign press following the ceremony was in the Taiwan Room. Fujian is the Chinese province directly across the Formosa Strait from the island.

Chinese Communist Party General Secretary Hu Yaobang, who also met with Thatcher earlier in the afternoon for nearly an hour at the headquarters of the party's Central Committee, also hailed the occasion as a "red letter day" and used a Chinese saying to describe China's attitude of sincerity.

"One is willing to pay a hundred kilos of gold for his reputation, but one is willing to pay a thousand kilos of gold for his credibility," a Foreign Ministry spokesman quoted Hu as saying. "The Chinese will implement this agreement in every respect because this concerns China's reputation in the world."

Thatcher, who flew into Peking Wednesday night and is scheduled to leave Thursday for Hong Kong before proceeding to Washington for talks with President Reagan on Saturday, also discussed East-West relations and the upcoming U.S.-Soviet arms control talks in her meetings here, Chinese spokesmen said.

In her meeting with Deng, Chinese Foreign Ministry officials said Thatcher "expressed serious concern over the nuclear arms race and the rivalry in developing weapons for outer space."

Thatcher told Deng it was imperative to maintain a constant contact and dialogue with the Soviet Union and reach an agreement on the basis of mutual respect, the official New China News Agency quoted her as saying.

Deng said China hoped the United States and the Soviet Union would make progress in their negotiations on the reducton of nuclear arms and that the deadlock would be broken "in the interests of the people of the world," the agency reported.

Thatcher was expected to brief Chinese leaders on her meeting in London Sunday with Soviet leader Mikhail Gorbachev. The Chinese were expected to discuss the upcoming visit to Peking of Soviet First Deputy Premier Ivan Arkhipov. But, said one western diplomat, "although the talks are likely to be substantive, neither side is going to say much that would detract from the main event -- the signing of the agreement."

The accord is expected to be ratified by both the British and Chinese governments by mid-1985. If things go well, Premier Zhao said the "basic law" governing Hong Kong after 1997, when Britain's 99-year lease expires, would be promulgated no later than 1990, according to the official Chinese news agency.

There has been increasing pressure for Hong Kong participation in the drafting of this basic law and Zhao said tonight that "views of the people in Hong Kong would be fully solicited" while the basic law was being drafted.

Zhao is expected to visit Britain in June 1985, Chinese officials said, and, in a surprise announcement from London, British officials said Queen Elizabeth would be visiting China in the latter half of 1986.