A visibly moved Secretary of State George P. Shultz told several thousand cheering Afghan refugees here today that they "do not fight alone" to expel the Soviet Union from Afghanistan. He pledged firm and continuing U.S. support.

Shultz, on a quick trip from Islamabad, addressed the turbaned and bearded men in the Nasir Bagh camp within sight of the hills of Afghanistan as "fellow fighters for freedom." Speaking in an unusually forceful, even fervent tone, he declared, "My message from the United States is simple--we are with you."

At the command of the refugee leader, three full-throated cheers roared up in reply, from row upon row of Afghan men sitting on the floor of the meeting hall.

Earlier, the spokesman for the refugees spoke to Shultz of a jihad, or holy war, against the Soviet occupation of Afghanistan. The spokesman, identified as Nazir Malik, said of the Soviet troops, "We have punished them in every part of the country" and reduced them to "beleagured captives in a state of siege" in a few surrounded cities.

Shultz, wearing an open-necked dress shirt without a tie in the steaming heat of this frontier area, sat with fingers laced and a grim expression on his face as he looked out on the sea of men and boys. When he stood up to speak he said the occasion was "very moving for me."

Nasir Bagh, with a refugee population of about 32,000, is one of dozens of camps containing nearly 3 million Afghans who have fled to neighboring Pakistan as a result of the political developments and fighting in their homeland. The camp is near the frontier city of Peshawar, headquarters of many of the rebel groups fighting against the Soviets inside Afghanistan, and is often visited by high-ranking foreigners.

In a reference to President Reagan's decision to sell grain to Moscow, the bearded, white-robed refugee spokesman noted that former president Jimmy Carter had imposed "certain embargoes" against the Soviets in retaliation for the invasion but that "now those embargoes have been lifted." Shultz made no reference to this in his response.

The spokesman gave short shrift to the indiret negotiations that have been taking place between the Soviet-backed Afghan regime and the government of Pakistan under U.N. sponsorship. Shultz referred to the talks, saying that from the U.S. point of view they will succeed only if the results include "removal of the Soviet forces, . . . self-determination for Afghanistan and the return of refugees with dignity and honor."

The refugees did not ask for help in the form of weapons, as they often have with other high-ranking visitors. This omission suggested that for the moment their countrymen have plenty of arms, covertly supplied by the United States, Egypt and other countries.

At his residence near Islamabad, Pakistan's capital, President Mohammed Zia ul-Haq told American reporters that "the Soviet Union has got itself stuck in Afghanistan" with its only military option being to bring in more troops and thereby generate even greater popular resistance.

"The Soviet Union after three years has realized that the military solution is perhaps not the one . . ., Zia said. "Either we have a status quo or try to resolve this politically." He quoted Soviet leader Yuri Andropov as agreeing in a conversation with Zia that "the political solution is the only answer" and that the United Nations is probably the most helpful sponsor of such a drive.

"Although in the 20th century I do not believe in miracles, I thought if we could pull a miracle in the 20th century it would be the successful conclusion of the U.N.-sponsored Geneva talks and the withdrawal of the Soviet Union," Zia said.

In a separate interview, Pakistani Foreign Minister Sahabzada Yakub Khan said that progress in the U.N.-sponsored talks has been "steady, meaningful and substantial," but that many key issues have not yet been addressed.

"It is not our impression that the Soviets are stalling or dragging their feet," Yakub Khan said. "Our impression is the Soviets are serious about this process of seeking a settlement."

The minister, who conceded that progress has been slow, would not estimate when the talks could come to a conclusion in which the Soviets would agree to withdraw their forces in return for guarantees that no further outside help would be furnished to Afghan insurgents.

"I would be disappointed if this runs into several years," Yakub Khan said. "I don't think it will run into that kind of period."

However, an independent Afghan observer in Peshawar said arrangements under discussion for cessation of fighting by the insurgents are "not practical."

Prof. Sayd B. Majrooh, chief of the Afghan Information Center, said the Soviets "need more convincing to come to the real point"--that an Islamic, nonaligned regime must come to power in Afghanistan.