Three times in three days members of the U.S. trade delegation in Beijing packed their bags and prepared to go home in defeat. Three times they unpacked and returned to negotiations.

In late August, President Clinton and his senior advisers became convinced that China's rulers were ready to come to closure on negotiations giving China membership in the World Trade Organization. That assessment eventually proved correct, but only after both sides went on what several senior U.S. officials yesterday described as a "roller-coaster ride" hurtling rapidly between hope and despondency.

In that sense, the long-elusive WTO accord struck by negotiators early Monday was a victory won in classic style for the Clinton White House--at the last minute, after teetering chaotically between success and failure.

On Friday, U.S. Trade Representative Charlene Barshefsky announced talks were stalled and she was ready to call it quits. The Chinese urged her not to leave.

On Saturday, after a meeting between Barshefsky and Chinese Premier Zhu Rongji, things were looking more upbeat. Clinton's aides prepared a statement hailing a deal that Clinton said he was going to read at 5:30 a.m. Sunday before flying to Europe. At 4:30 a.m., White House aides called it off after Barshefsky and national economic adviser Gene Sperling reported that the deal was not done.

Later, as Clinton flew across the Atlantic, negotiators called Air Force One to report even worse news: Talks had stalled again, over such issues as foreign ownership of telecommunications firms, and agreement looked unlikely.

It was not until shortly after midnight Washington time--Monday afternoon in Beijing, Monday morning in Ankara, Turkey--that things looked bright again. Clinton was pulled out of the shower in his hotel room to take a call from Barshefsky and Sperling.

As it happened, they were calling on a cell phone from a women's bathroom at the government offices where negotiations were taking place. It was the only convenient place where they could spirit away to get some privacy. White House officials, flush from success, yesterday called it "bathroom-to-bathroom diplomacy."

U.S. officials closely connected to the talks said the brinkmanship that marked the final stages of the trade talks was more than the usual last-minute posturing for position that marks many negotiations. The U.S. delegation was entirely prepared to leave--on Monday, the bags were already on the way to the airport--and it seemed clear to the U.S. side that at least some Chinese officials would have been perfectly content to let that happen.

"There's no question that for the first couple of days we were frustrated," Sperling recalled yesterday, "that we did not feel there was the type of movement that would show that they really were serious about coming to an agreement."

But senior White House officials said ultimately it was most notable that two people were determined that the talks end with a handshake: Chinese President Jiang Zemin and Premier Zhu.

Their determination to keep the negotiations alive reflects an apparent belief that "China's future lies with the West" and toward greater integration with the world economy. Other influential Chinese leaders, including Li Peng, the former premier and second-ranking official in China's Communist Party, are far more skeptical of the WTO and the changes required for the country's economy.

Whenever talks were on the verge of breakdown, U.S. officials said Zhu intervened, including as late as Monday morning, according to Sperling and Barshefsky. While the two senior officials were huddling in the hallway Monday morning, after Sperling had already once walked out of the talks in a huff, Sperling recalled that, a Chinese woman "comes up to us and says, 'Premier Zhu is in the building and would like to see you right away.' "

While Zhu refused to yield on some points--not letting foreign companies have 51 percent control of telecommunications companies--he made other concessions and made plain that the Chinese were done with what seemed to the U.S. side to be an endless succession of new objections and conditions.

For Clinton, the WTO deal represents a months-long effort to revive a troubled China relationship. China was deeply offended when he turned down a WTO deal last April, after senior aides expressed concerns that it would be politically unsalable at home. The next month, the relationship turned far worse, after the U.S. bombing of the Chinese embassy in Belgrade during the NATO air campaign against Yugoslavia.

On Aug. 27, Clinton wrote Jiang urging renewed negotiations. What followed was more than two months of constantly changing signals from Beijing. Clinton, aides said, was frustrated when Jiang did not seem interested in moving the issue forward at an Asian economic summit in New Zealand in mid-September. But on Oct. 16, he talked with Jiang again and was more encouraged.

Days later, Treasury Secretary Lawrence Summers went to Beijing. He came back convinced that China wanted to see a broad outline of a U.S. proposal, rather than negotiating each point on an item-by-item basis. The United States sent such an outline to Beijing later that month.

On Nov. 6, Jiang and Clinton spoke again. Clinton said he wanted to send Barshefsky back over--but only if the negotiation was serious and a deal was likely. Jiang urged that the final round of talks begin.

But, as talks dragged, Barshefsky said she and Sperling faced a daily effort to keep their spirits high. Each day the U.S. delegation came up with a song to fit the changing mood. "We assigned a theme to each day," she recalled. "It kept everybody going."

On Friday morning, it was a bastardized version of Aretha Franklin's "Respect."--"What I need, baby, you don't got; What you need, baby, I ain't gonna give."

Fortunately for the U.S. delegation, and for Clinton, the song sheet changed by Monday.

Harris reported from Washington and Laris reported from Beijing.