Just as in politics everywhere, the Islamic republic established here has its winners and losers. But the political battle can be a more bruising experience in Iran than most places these days.

Iran's defense minister, Taqi Riahi, and military Police Commander Gen. Saif Amir Rahimi seemed ready to bear witness to that tonight following a pilgrimage by the nation's provisional prime minister and his leading Cabinet ministers to the holy city of Qom.

There, in the presence of Ayatollah Ruhollah Khomeini, the dour, 79-year-old leader of the revolution, a week-long power struggle in the top echelons of Iran's freewheeling military establishment was apparently resolved behind closed doors.

The winner appeared to be Riahi, who, after resigning in a pique when his decision to fire Rahimi was overturned by Khomeini last week, decided he would be back at his desk tomorrow running the provisional government's remnants of a once-powerful armed forces.

The loser clearly was Rahimi, a flamboyant former colonel of Shah Mohammad Reza Pahlavi's army who emerged from forced retirement after the revolution in February to head the new government's military police units.

Rahimi, who made a bold bid for power by publicly declaring "It's the Cabinet or me," left the meeting convinced he will have to step down, according to sources close to the general.

"This is the shootout at the O.K. Corral," a confidante of Rahimi said as the military commander headed toward Qom with what was said to be an ultimatum for the Cabinet to be proffered in the presence of the ayatollah.

Anticipating the result of the meeting, the confidante said of Rahimi, "He's popular, but not powerful. There are a lot of people in the government who aren't popular, but are powerful."

Provisional Prime Minister Mehdi Bazargan also went to Qom, taking with him ForeiGn Minister Ibrahim Yazdi, Justice Minister Ahmad Sadr Haj Seyed Javadi and other Cabinet ministers.

The meeting immediately touched off rumors of a major Cabinet reshuffle, although government spokesman Sadeq Tabatabai said the talks concerned border problems in Khuzestan and Kurdestan and unemployment in $&(WORD ILLEGIBLE Iran. Other sources said the feud between Riahi and Rahimi was the prime subject of the meeting.

Apart from drawing attention to growing turmoil in the command of Iran's revolutionary armed forces, the episode offered a revealing glimpse of the volatile nature of political life in Iran today and the extent of Khomeini's authority.

As so many other government leaders have done before him, Riahi learned that nobody quits the government without approval of Khomeini. And Rahimi, a charismatic figure with a broad following, presumably learned that political homicide does not necessarily entail murder.

Before heading for the Qom meeting, the irascible Rahimi was quoted in the Persian newspaper Kayhan as saying: "I will not give away anything, for I have learned from the imam (Khomeini) that one must fight for one's rights. The only way I can be dispensed wi th is by murder, and I have no fear of it."

The controversy erupted last week when Rahimi summoned foreign correspondents to his office in an army garrison in downtown Tehran and darkly alluded to a military plot to discredit the Islamic government. Claiming that senior officers had comspired to unseat him, Rahimi refused to identify the conspirators, but hinted that he would at a later press conference.

A few hours later he was fired by Riahi, but the dismissal was overturned on direct orders of Khomeini. Rahimi, a longtime friend of the ayatollah, had been forced into retirement by the shah for condemning foreign influence in the Army, but he was drafted back into service when the revolutionary leader returned from exile early this year.

Riahi reportedly brooded about the reversal for a week, refusing to see any visitors, and then he began telling newsmen that he had resigned, although he refused to say why.

Rahimi, who seemed unable to disguise his pleasure at the turn of events, called foreign reporters to his garrison again on Monday for a press conference and a showy parade of his military police units, even though he had been ordered by the government not to make political speeches or hold press conferences.

As reporters wilted in the suffocating heat, about 500 recruits and a small unit of the black-shirted "Fedayan-e-Khomeini," Rahimi's personal guards, goose-stepped across the parade grounds in time with a military band's unlikely selection of the World War I marching refrain, "The Yanks Are Coming."

Then in his office, Rahimi said that he was not going to discuss the "conspiracy" or name names.

"The last time I saw you, I was dismissed a few hours later. I wouldn't be surprised if it happened again," Rahimi said. He insisted his allegations were "absolutely true," but hinted broadly that he had been pressured not to drag politics into Army matters.

Rahimi said that while many-caliber weapons had been taken during the revolution, the heavy weapons are intact and the Air Force has "1,000 superb pilots for the [F4] Phantoms."

A .45 caliber Colt revolver at his side, the gregarious general conceded that after a revolution, it was inevitable there would be some inefficiency in the army. But he insisted Iran has the "biggest and best equipped" Army in East Asia and the Middle East. CAPTION: Picture, Iran's military police commander, Gen. Saif Rahimi, says the Air Force has "1,000 superb pilots" for its F4 Phantom jets, like the ones shown here flying over a Tehran rally in support of Ayatollah Khomeini. UPI