KARACHI, PAKISTAN, AUG. 17 -- President Mohammed Zia ul-Haq, U.S. Ambassador to Pakistan Arnold Raphel, the senior U.S. military officer here and several of Pakistan's top generals were killed today when their C130 Pakistani transport plane exploded in midair shortly after taking off from Bahawalpur in the eastern part of the country.

Ghulam Ishaq Khan, the chairman of the Pakistani Senate who took over as acting head of state as prescribed by the constitution, declared a state of emergency and said in a television address that "sabotage cannot be ruled out" as the cause of the explosion, which killed 32 persons.

Khan announced that general elections scheduled for Nov. 16 would proceed as planned and that the constitution would remain in force. A 13-member emergency committee was formed to govern the country, including five senior ministers, provincial leaders and the heads of the three branches of the armed forces.

A senior Pakistani security official who inspected wreckage of the aircraft said that "without any doubt it was a subversive act." The wreckage was found about 80 miles from the Indian border. He described the wreckage as giving "an initial hint that the plane exploded due to a ground action," but he offered no further explanation.

Civil and military security officials investigating the explosion described it as a "full-fledged terrorist operation" and said they had suggested utmost security for the president because of the flurry of threatening statements against Pakistan by the Soviet and Afghan governments in the past several months.

Pakistan has been the principal funnel for aid to the anticommunist resistance forces fighting the Soviet-backed government of Afghanistan.

If it were proved that sabotage was behind the explosion, the number of possible suspects would be large because, in addition to its disputes with Moscow and Kabul, Pakistan has strained relations with India and internal trouble with some militant ethnic groups and domestic critics who oppose Zia's policies.

State Department spokeswoman Phyllis Oakley said today that the United States had no information on the cause of the explosion.

While the cause of the disaster remained in doubt pending an investigation, western diplomats in Islamabad said the plane was probably destroyed by a bomb placed aboard or an antiaircraft missile.

Pakistani and U.S. officials were sifting through the wreckage at the scene of the crash, which had been put under Army control. Troops blocked thousands of people from reaching the site, residents of Bahawalpur reported by telephone. They said they saw Pakistani military aircraft and helicopters performing what they described as a rescue operation.

The State Department said the plane went down 10 minutes after takeoff as Zia and his senior military commanders were returning from a demonstration of a new U.S. M1 tank that Pakistan was interested in buying. The senior U.S. military attache in Pakistan, Brig. Gen. Herbert Wassom, was also aboard. He and Raphel were the only Americans to die in the crash.

The death of Pakistan's authoritarian ruler, who seized power in a military coup in 1977, threw the future of Pakistani politics into turmoil.

Zia maintained control by martial law until December 1985, when he passed power to a controversial civilian government. Last May he reassumed full control by dismissing his prime minister and Cabinet and dissolving the lower house of Parliament.

Pakistan's chief opposition leader, Benazir Bhutto, whose father was deposed and later executed by Zia, said that while she mourned the deaths of the U.S. ambassador and other military officials she did not regret the death of Zia. "Life and death is in God's hands," she said.

President Reagan, through his spokesman, expressed sadness at the loss of Zia and praised his work in cooperation with the United States to secure the withdrawal of Soviet troops from Afghanistan through the Geneva accords.

"The United States was fortunate to have such a friend in President Zia, but our support for Pakistan is not dependent upon any individual," Reagan said in a formal statement.

In an indication of the important role the Army may continue to play in Pakistani politics, Khan moved quickly to fill the void left by the death of several leading generals in the crash. He appointed Gen. Mirza Aslam Baig as the new Army chief of staff. Zia had served as commander in chief of Pakistan's Army since 1976, a post he kept along with the presidency.

Another prominent victim in the crash was Gen. Akhter Abdul Rehman, a relative of Zia and the chairman of the Joint Chiefs of Staff. Rehman, 64, was the former chief of the country's top intelligence service. Until 1987, Rehman also ran the intelligence agency's Afghan operation, which includes supplying western and Arab arms to the Afghan mujaheddin, or rebels, and coordinated the guerrillas' military strategy and training, security officials in Islamabad said.

Khan said he would seek to maintain an orderly transition and promised there would be no major changes in foreign policy. Under Zia, Pakistan became a major aid recipient and close ally of the United States, especially in the support it provided for Afghan rebels.

"The country will emerge from this crisis situation more strong and united," said the acting president in his address to the nation. He said that Pakistan will hold elections as scheduled to show that "our commitment to democracy is stronger than ever."

However, he declined to give any details about the elections, from which Zia had barred regular political parties. The main political opposition alliance has been demanding in rallies across the country that political parties be allowed to participate.

Khan decreed 10 days of national mourning and said schools and government offices would close for three days.

Police forces were placed on alert in Karachi, and a heavy police presence was also reported in Rawalpindi and Lahore. But no major disturbances were reported across the country.

People here on the streets of the biggest Pakistani city received the news of the crash with shock.

In some parts of the city Bhutto's supporters took to the streets. Witnesses told Reuter news agency that troops had taken up positions at key points in Karachi around midnight and set up camp outside a stadium. "They are taking precautions," a policeman said.

Among the last of Zia's visitors before his death was Sadruddin Aga Khan, the U.N. commissioner for Afghan refugees, who is currently engaged in drawing up plans for the return of more than 5 million Afghan refugees.

Officials present at their meeting yesterday said that Zia had again forecast the collapse of the Soviet-backed Najibullah government in Kabul before the end of this year.