Outside the Church of St. Stanislaw Kostka, the Polish crowd was in a frenzy as Vice President Bush and Solidarity leader Lech Walesa appeared by surprise on the balcony last Monday morning. "Solidarity! Lech Walesa! Long live Bush! Long live Reagan!" they chanted, mostly in Polish, as Bush was handed a microphone his staff had secretly wired in place the night before.

This was the climactic moment of Bush's four-day visit to Poland. He had slipped away from the Polish security agents inside the church and had taken Walesa up a narrow stair to the balcony where they could be seen for the first time by thousands of Poles restrained by barricades in the streets beyond.

The scene was later viewed by millions of Americans on television and is regarded by Bush campaign strategists as a masterpiece of political theater for a candidate who is often regarded as bland and uninspiring. Such a moment of triumph, recorded by Bush's campaign camera crew for use in future commercials, fulfilled one of the vice president's chief domestic political goals in going to Poland.

But the balcony scene was also revealing of a hidden story behind Bush's visit to Poland, a tale of improbable players and unconventional methods that, in the end, was most instructive about the vice president.

Even at the emotional zenith of his visit, as he stood on the church balcony, Bush came across as extraordinarily cautious and hesitant, trying to avoid a provocation of his communist government hosts while openly backing Solidarity, the banned trade union. Bush tried constantly to walk a fine line that would not offend either side.

Regardless of his low-key demeanor, Poles greeted Bush with a remarkable outpouring of affection, stemming in part from President Reagan's strong stand against the suppression of Solidarity. "I don't think anyone prepared us for what we found," said a Bush adviser who viewed the outcome as a valuable boon to his campaign.

Bush returned to the United States yesterday after a round of meetings with allied leaders that were designed as a foreign policy prelude to the official launching of his campaign Oct. 12.

Although State Department officials at first discouraged Bush from going to Poland, the vice president found encouragement from an unlikely source: Zbigniew Brzezinski, national security adviser to President Jimmy Carter, the sources said.

Brzezinski realized the trip had the potential to spark an outpouring of pro-American sentiment from the Polish people, as well as advance relations with the Jaruzelski government, the sources said.

Brzezinski met with Bush last summer, and it was decided to use him as an intermediary with the government of Poland's leader Gen. Wojciech Jaruzelski. The sources said Brzezinksi carried a message from Bush to the Polish leader that Bush would be willing to make a visit, as the highest-ranking U.S. official to come to Poland since 1977, so long as he would be allowed access to differing elements of Polish society, including Roman Catholic church leaders, intellectuals and leaders of Solidarity.

"It had to be a trip with the Polish people," said a senior Bush aide.

Brzezinski, now at the Georgetown Center for Strategic and International Studies, is the eldest son of an aristocratic Polish diplomat who served before the Nazi invasion. Brzezinski confirmed he played a role in helping Bush but said reports of his involvement had been "greatly overestimated." He would not comment further.

As planning intensified, Bush aides, including chief of staff Craig L. Fuller and pollster Robert Teeter, began to work on an agenda, along with John Keller, Bush's director of advance. Their early list included meetings with Jaruzelski, Walesa, church leaders and Polish intellectuals. It also included a visit to the grave of Solidarity's hero Father Jerzy Popieluszko, who was murdered in 1984 by Polish internal security forces. The gravesite -- a large granite cross on a gentle knoll -- is just inside the fence of the St. Stanislaw Kostka church. The fences are adorned with Solidarity banners.

Long negotiations ensued over what Bush would see and do in Poland. According to a senior Bush assistant, Bzrezinski is credited with a "breakthrough" discussion persuading the Poles that Bush must have open events with spontaneous exposure to Polish crowds. The outcome of the negotiations was a mixture of events sought by the Polish government, such as the vice president's visit to a television tube factory and those sought by Bush, such as the ceremony at Popieluszko's grave.

In policy terms, Bush's mission was to make it clear to Jaruzelski that long-sought economic aid from the West would come only after internal political and economic changes.

At the same time, in a separate meeting with Walesa, Bush found the Solidarity leader approving of his approach and urging the United States to visibly dangle the promise of more aid in exchange for reform. Walesa complained that at the current pace of government reforms "it will take 100 years to get where we need to be," according to a source who attended.

Beyond these policy talks, the Bush mission became a daily cat-and-mouse game between his entourage and the Polish authorities.

On Sunday it became clear that while Bush was being given permission to move about Warsaw, the authorities had quietly taken the approach of subduing the response to his visit. His itinerary was not publicized in the state-run media, for example; U.S. officials had it broadcast by Voice of America. On Sunday, when he attended Mass at St. Margarets Church in Lomianki, plainclothes Polish security agents filled the crowd outside the church, where Bush received a noticeably low-key reaction.

Before Bush arrived, two of the security agents were seen rehearsing in broken English what they would say if asked by U.S. reporters. "What you think of Bush visit?" one asked the other. "Very good for relations," the other replied.

That night, working on the premise that surprise was essential, a team of Bush aides went out to the site of Popieluszko's grave without telling the government. Working in the cold night under the direction of Keller, the Bush aide, they secretly wired a microphone and public address system into the balcony. Meanwhile, the embassy quickly processed a photograph of Bush and Walesa taken Saturday night and put it in a silver frame with the vice presidential seal to be left by Bush at a special display dedicated to the priest inside the church.

After Bush laid a wreath at Popieluszko's grave with Walesa at his side -- he took a Solidarity banner out of his pocket and put it on the wreath -- the day's events did not follow the original plan. Instead of exiting the church as Polish authorities had expected him to do after viewing the display, Bush was led away by his aides to the balcony, where he and Walesa were greeted enthusiastically. A dash of dramatic color was added to the scene with a large red-and-white streamer erected the night before by the Bush team.

To those watching below, Bush appeared wooden and hesitant before lifting his hand in a triumphant "V" for victory sign, the Solidarity symbol and a dramatic open endorsement of Walesa. A close aide said later that Bush was fearful of making a gesture that would be so provocative as to spoil his talks with the government.

After the church appearance, Polish government officials grew visibly anxious about the content of Bush's planned televised address that evening. They complained of unexpected "schedule changes," a Bush aide said, and they removed the Polish flag from Bush's limousine.

At an official meeting, Jan Kinast, deputy foreign affairs minister, passed a note to chief of staff Fuller asking for the Bush speech text. Although U.S. officials had promised it in English two hours before the broadcast, they did not release the text to the Poles or American reporters until just before Bush went on the air because the vice president was making changes. Officials said one change was to add a phrase at the begining of thanks for "my government hosts" for their hospitality; another was to make stronger his words embracing Solidarity; and finally Bush added at the end, "Long live Poland."

Before he departed, Bush and his entourage were treated to some comic scenes as the American and Polish officials gently jockeyed for best advantage. For example, while Bush's campaign camera crew was in position to get the best footage for his political advertisements, there was a Polish video camera, too. According to a senior Bush aide, it was carried by a Polish agent who was eager to get tape of all the people around Bush for intelligence purposes.