In Iran yesterday, the specter was raised of a military coup against the fragile civilian government of Prime Minister Shahpour Bakhtiar. In France, religious opposition leader Ayatollah Ruhollah Khomeini rejected President Carter's appeal for support of the Bakhtiar government. In Washington, a more optimistic note: State Department officials voiced the belief that there are prospects for stabilization of the newly formed government in Tehran as an outgrowth of negotiations between military and religious leaders as well as opposition politicians.

Negotiations involving all the principal civilian and military rivals for power in Iran have begun in Tehran and the Carter administration believes that the talks can lead to a stabilization of the Iranian crisis and to "a new national consensus," a U.S. official told reporters yesterday.

Stressing that events in Iran remained unpredictable, the official nonetheless delivered an assessment that contrasted sharply with reports from Tehran and France of the continuing threats to the government of Prime Minister Shahpour Bakhtiar.

Relative optimism has been a constant feature of high-level Washington assessments of the events in Iran that drove Shah Mohammad Reza Pahlavi from the country on Tuesday, a month after President Carter predicted the shah would surmount the crisis.

The shah's departure and the beginning of talks on Iran's political future by representatives of the Iranian military, exiled Moslem leader Ayatollah Ruhollah Khomeini, Bakhtiar's cabinet and the political opposition known as the National Front have led to "a lessening of reports of the possibility of a military coup," the official said.

Under the rules of the briefing, the official cannot be publicly identified.

In listing the political forces negotiating to restore order, the official omitted mentioning the shah and his supporters. He said that the question of whether Iran would continue to be a constitutional monarchy "will have to be discussed."

The overall tone of his remarks, those of President Carter's news conference Wednesday and of testimony to a congressional subcommittee Wednesday by the State Department's top Middle East expert, Assistant Secretary of State Harold Saunders, suggested that the administration now sees the shah as a spent political force and is banking totally on Bakhtiar's government to restore order and open a transitional era in Iranian politics.

Signs emerged yesterday that the shah may yet be hoping to gain leverage on the Carter administration and seek to stage a comeback with its support, diplomatic sources reported.

After his current stay with Egyptian President Answar Sadat in Aswan, the shah will probably visit King Hassan II of Morcocco, another Arab leader influential both with the administration and with Republican leaders, especially former secretary of state Henry A. Kissinger.

During his visit to Washington in November, Hassan strongly pressed Carter to make sure the shah did not fall. The shah reportedly is considering visiting other Middle Eastern leaders friendly to the United States before heading for the United States next week, U.S. sources said.

The domestic political impact the shah's fall could have was also brought into public view yesterday by the fact that the shah and Sadat met together in Aswan with former president Ford, who is vacationing in Egypt.

Ford spokesman Bob Barrett told reporters after the three men met in a heavily guarded hotel on an island in the Nile that Ford was "very, very sad" about the turmoil in Iran. "He knows what a valuable ally the shah has been."

White House aides said that Ford's meeting with the shah was not a cause of concern from a foreign policy viewpoint. But one senior official in the administration conceded that "it could be a problem if Ford came back preaching that we let the shah down."

The Associated Press reported that the shah appeared stronger yesterday than he did on Wednesday when he arrived in Egypt looking gaunt and weary. He refused to see reporters.

U.S. officials said that Sadat took the initiative in inviting the shah to Egypt, and relayed his request three times through U.S. channels before the shah accepted.

The official briefing reporters yesterday said that the administration had indications that all of the parties negotiating on future political arrangements, including Ayatollah Khomeini's group, "want an end to the violence" that has paralyzed Iranian political and economic life and halted oil exports.

He did not give details of the negotiations, and when asked refused to speculate on whether the shah might be politically active while he is in the United States for what is expected to be an extended stay.

The shah's visit apparently is being prepared by Ardeshir Zahedi, who says he is still Iran's ambassador to Washington despite statements from Tehran by a foreign ministry spokesman that Zahedi is resigning. Zahedi was in Lubbock, Tex., Wednesday, visiting some members of the shah's family, and news agencies reported from there yesterday that the shah is expected to go to Palm Springs, Calif., next week.

The Carter administration expects that if the military leaders now negotiating with the other factions reach agreement on a new political formula, "there should be support down the line" from the troops and a coup can be forestalled, the U.S. official said.

He said that the administration still had not established direct contact with Khomeini, but had found in meetings with Khomeini aides "a certain amount of understanding" of past U.S. support for the shah's government. He predicted that the current wave of anti-American feeling in Iran could be overcome.

U.S. contacts with the contending factions "helped create a sense of the importance of their sitting down together" to sort out new political arrangement, the official said, but he gave no details.

The United States would not oppose a solution agreed upon by the groups. Bakhtiar, who was installed by the shah, will be seen by many Iranians as representing the shah's interests in the talks, while the Iranian military has close and separate links to the United States, a probable factor in the administration's willingness to agree in advance to abide by the negotiations' outcome.

The administration is believed not to have ruled out the possibility that the provisional council Khomeini proposed could come into being and begin working on a plan for a constitutional assembly while the Bakhtiar government remains in place and restores order. The official offered no direct comment on such possibilities.