The best chance to date for political compromise in Iran apparently collapsed this afternoon because of weakness, pride and bad luck associated with the anarchy of free-wheeling revolution.

Healthy just before midnight yesterday, sick by midmorning today, the deal succumbed after lunch, leaving Iran with what in normal circumstances would be a lame-duck prime minister and increased risk of civil war.

Only the few remaining optimists here believe that this strategically important oil-producing nation can now avoid continued turmoil for the foreseeable future.

Basically, the proposed deal turned on sending Prime Minister Shahpour Bakhtiar to Paris to arrange with Ayatollah Ruhollah Khomeini an orderly, if purposely vague, turnover of power to allow Iran to end its monarchical past and begin a republican future.

With the country shut down by a general strike, the armed forces on the brink of splitting, a growing chorus of once conservative Iranians calling for armed struggle, there remained a relentless attention to detail.

According to sources close to the negotiations, it had been agreed that Bakhtiar would give Khomeini a letter tendering his resignation in exchange for a lette from the ayatollah asking him to stay on as caretaker prime minister of a provisional government.

Bakhtiar would resign once he had met Khomeini, rather than before, as the 78-year-old Moslem leader had previously demanded.

The deal was put together yesterday thanks basically to the weakness of the parties concerned. Khomeini. frustrated by Bakhtiar's closing of the Tehran airport to prevent his return in triumph after 14 years of exile, was confronted with the choice of backing down or escalating his demands and risking civil war against the armed forces behind Bakhtiar.

No Moslem leader as driven as Khomeini could escape the conclusion that if such a conflict occurred -- as his ever more radical followers demanded by calling for a holy war -- the only winer in a shootout between the two conservative forces would be the left they abhor.

Bakhtiar and the armed forces also were out of maneuvering room. Their 72-hour airport shutdown was about to expire and they feared escalating violence unless Khomeini returned home promptly.

No matter what the tough military commanders said in public, they, too, were torn by a desire to preserve the unity of the armed forces, already sorely strained by mass demonstrations of disaffected troops and desertions.

Less than two weeks after saying goodbye to the shah, they did not relish going through the same routine with Bakhtiar, even if he were to make a face-saving deal with their archenemy, Khomeini.

All these factors allowed the parties concerned to bluster in public -- Khomeini saying "never" to Bakhtia if he did not resign, the generals tightening up martial law and the prime minister announcing that the airports would remain closed.

Behind the scenes in negotiations, which the parties denied even existed, they were dealing with hopes their various interlocutors would find a solution. But as Khomeini's vocal aides are the first to admit in private, it is not easy to deal with a principal thousands of miles away who refuses to come to the long distance telephone and prefers to act via written messages and rival -- or at least often discordant -- aides.

Khomeini also made things more difficult for his local friends by jumping the gun last week in announcing that he was determined to return to Iran before they could smooth things over with the military.

When the local negotiatos, after countless telephone calls to Paris, finally yesterday afternoon believed only details remained to be solved, Bakhtiar went on the radio and announced that he would leave to see Khomeini in Paris in 48 hours.

He was convinced he had gained a desperately needed breathing spell to prevent Khomeini's hard-core supporters from trying to storm the airport or provok some other violence. Contradictory statements emanating last night from Khomeini's assistants in Paris were interpreted here as a helpful smokescreen.

The problem, it turned out, was that Khomeini had never been informed in detail of the proposed deal, and the violence yesterday and today persuaded him to scuttle the compromise for fear of letting down his followers.

"We now have to find another formula," one of Khomeini's lieutenants said here today.