Hundreds of police, firing tear gas and swinging heavy staves, succeeded today in containing what has planned as a massive demonstration demanding the immediate resignation of Prime Minister Zulfiqar Ali Bhutto.

The embattled prime minister, looking buoyed by the failure of the demonstration, told a crowd of supporters that he had received a written appeal from Secretary of State Cyrus R. Vance seeking "quiet" talks to settle differences between the United States and Pakistan.

Bhutto charged earlier this week that the United States had financed a "colossal" conspiracy to force him from power.

[In Washington, a State Department spokesman said Vance wrote Bhutto after the prime minister made his allegations of American support for his opponents. The spokesman said Vance reaffirmed that the United States was not interfering in Pakistan affairs and expressed willingness to discuss differences.]

Waving a sheet of paper which he said was Vance's letter. Bhutto told a large, cheering crowd outside the U.S. Information Service library here that he was "willing to talk, but I will not compromise on principle."

A spokesman for the U.S. embassy in neighboring Islamabad, the national capital, confirmed that a letter from the secretary of state was delivered to the Pakistan government yesterday. The spokesman said he could not comment on whether the United States was disturbed by Bhutto's revealing at least part of the contents of an official letter seeking private discussions.

It was understood, however, that the section of the letter about which Bhutto spoke was just a friction of its total contents. A top Pakistani government source said earlier this week that Vance had written Bhutto a few weeks ago suggesting the two governments resume discussions on U.S. objections to Pakistan's buying a nuclear reprocessing plant from France.

Bhutto spoke to the crowd during a one-hour jeep tour of sections of this old British colonial garrison city where pitched battles between police and anti-Bhutto demonstrators occurred this morning.

His convoy of troop-laden jeeps and trucks was enthusiastically received as it moved through the streets, many of them littered with brickbats and remnants of burned tires and other charred refuse. Although the fighting went on for about eight hours, there were no known fatalities.

Pleased by his reception, Bhutto went on from his talk outside the U.S. information center to the nearby Intercontinental Hotel, where the acting president of the opposition Pakistan National Alliance was detained under police guard throughout the day.

The police had feared that the leader, Pir Sahib Pagaro, who is also a revered Moslem religious figure, would have stirred the demonstrators on to greater violence.

After a 45-minute meeting with the Pir, Bhutto told reporters who had asked whether there would be a negotiated settlement with the alliance, "I am hopeful about the future."

Bhutto was understood to have called an unscheduled session of his Cabinet late tonight and there were unconfirmed reports that he would meet Sunday with the jailed leaders of the nine-party opposition alliance.

Today's demonstration had been planned as the climax of nationwide protests that have virtually crippled Pakistan for nearly two months. Bhutto's opponents have demanded his resignation and new national elections to replace those held in early March which, they claim, were massively rigged in the prime minister's favor.

As many as 300 persons have been killed by police and army troops since the onset of the demonstrations.

Today, the army was notable in Rawalpindi by its absence.

Thousands of police and paramilitary forces, many of them trucked in from outlying provinces, maintained extraordinary discipline in keeping the demonstrators from massing. Each time a small knot of angry men collected, police either waded into their midst swinging heavy canes or fired tear gas canisters.

Two heavy, British-made armored cars, equipped with longrange tear gas firing tubes, lobbed canisters into the rabbit warren of back streets leading onto Murree Road, the intended route of march to Bhutto's official residence.

Although the violence was low key, by the standards of the anti-Bhuto campaign, a group of 1,000 angry university students managed to burn a post office, the headquarters of the police regional anti-corruption division and the division superintendent's car.