Rashid Karami, Lebanon's Sunni Moslem prime minister, resigned today, bringing down his crisis-ridden national unity Cabinet following 16 hours of fierce intra-Moslem combat that involved Palestinian guerrillas.

Hospital spokesmen reported that 29 persons were killed and 169 were wounded during the most intense battles on the streets of predominantly Moslem west Beirut in more than a year. Gunmen poured into the streets last night. Deafening battles with rockets, tank shells and machine guns raged until midmorning today, trapping residents in basements and hallways.

After the fighting was over, fires burned out of control on commercial and residential streets and the once elegant Hamra district was lined with scorched and blackened cars.

Victorious Druze and Shiite militias later paraded through the streets in military convoys, shouting and flashing victory signs.

In the battles, which Karami characterized as "conflicts among brothers," the Sunni Moslem Morabitoun militia, aided by Palestinians, was defeated by two powerful rivals: Justice Minister Nabih Berri's Shiite Amal militia and Tourism Minister Walid Jumblatt's Druze-dominated Progressive Socialist Party militia.

The violent split in Moslem ranks shattered the fragile truce among Lebanese Moslem political leaders who had joined together in a government of national unity last year and dragged the country deeper into the thicket of tribal feuds, increasing the uncertainty of when and whether any reconciliation might be possible.

The precarious authority of Lebanese President Amin Gemayel, a Maronite Christian, already had been weakened last month when Christian hard-liners revolted against him, charging that he was too closely allied with Syria. Gemayel asked Karami today to stay on with a caretaker Cabinet.

State Department spokesman Bernard Kalb said in Washington that Karami's resignation "comes at an untimely moment. We hope that a new government will be rapidly formed and that it will enjoy the full support of the Lebanese people," he added.

The Moslem fighting was something of a replay of similar battles a year ago, but it appeared this time to go beyond old Lebanese feuds and represent larger divisions in the region between Syria and Yasser Arafat's Palestine Liberation Organization.

Palestinians loyal to Arafat fought alongside the Morabitoun last night and have been rumored to have donated large sums of money to Beirut's Sunni Moslems.

The fighting began ostensibly as a quarrel over a militia office in an area contested by the Shiite Amal movement and the rival Sunni Moslem Morabitoun. It came only hours after Berri and Jumblatt returned from Damascus following consulations there with Syrian leaders.

The two ministers had declared upon their return to west Beirut that they were forming a joint military command of their militias to check lawlessness and deteriorating security conditions in west Beirut.

Berri, in a cryptic statement, blamed the fighting on "Arab hands" who he charged had carefully planned the street fighting by "exploiting sectarian" sensitivities in Lebanon.

It was believed here that the veiled remark referred to Syria's opposition to the return of Palestinian guerrillas loyal to Arafat to the refugee camps on the outskirts of Beirut, especially at a time when Arafat has moved closer to Syria's foe, Jordanian King Hussein.

It was unclear how many PLO fighters have infiltrated back into Beirut since their ouster after the Israeli invasion in the summer of 1982, but there have been several recent skirmishes between Berri's Shiite militiamen and guerrillas in the camps as the Shiites have attempted to block the PLO from staging a comeback in the capital.

Berri described the fighting as an "unexpected nightmare," although there had been indications earlier of unrest. There has been friction between Amal fighters and Palestinian guerrillas in the camps on the outskirts of Beirut.

Amal has encircled the camps for more than a year in a bid to contain the guerrillas and prevent them from staging a comeback. Palestinian sources said Amal has been searching the camps for arms in the past two weeks and brief battles were reported yesterday.

As the Shiite and Druze militias took on the Sunnis and their Palestinian supporters in the streets of Beirut, Israeli warplanes attacked a Palestinian guerrilla base in eastern Lebanon's strategic Bekaa Valley while Israeli troops raided another Shiite Moslem village in south Lebanon, according to The Associated Press.

AP reported from Tel Aviv that Israeli military sources said the target was a headquarters and training base of the Marxist Democratic Front for the Liberation of Palestine.

During the street battles in west Beirut, Amal seized control with tactical assistance and ground support from Druze fighters of the Progressive Socialist Party.

Progressive Socialist Party militiamen sealed off seafront areas under their control, cutting off access roads and allowing Amal to zero in on fleeing Morabitoun and Palestinian gunners.

Remaining pockets of Morabitoun and Palestinian fighters were routed after putting up stiff resistance throughout the night.

"What can I say to my people?" Karami asked in the statement announcing his resignation today. Commenting that injustices to Sunni Moslems had reached dire proportions, Karami described last night as a "cruel and brutal night."

Karami, 63, who has been prime minister 10 times since Lebanon gained independence, formed his Cabinet in April of last year after a Syrian-backed uprising of Moslem rebels brought down the government of former prime minister Shafiq Wazzan and led to the abrogation of the May 17 Lebanon-Israel withdrawal agreement.

Karami said no one could justify what had happened "and my response to you is the resignation of the national unity Cabinet."

Last week, the prime minister declared he would boycott his own Cabinet's meeting until security measures involving the dispatch of Army units to the embattled port city of Sidon could be implemented. Both Berri and Jumblatt had been staying away from Cabinet meetings for weeks.

Education Minister Selim Hoss, also a Sunni Moslem, upstaged Karami's resignation this morning by announcing his own and expressing bewilderment at Karami's silence.

According to UPI, Berri belittled Karami's resignation, saying it was "the result of a few shells" hitting Hoss' house.

Berri's house was hit by four rockets during the heated battles.

Beirutis staggered out of their homes at midday today to inspect the damage in their streets. Fires billowed out of several buildings in the Corniche Mazraa district, the Morabitoun's last stronghold. Amal and Progressive Socialist Party fighters hit the Morabitoun radio station with rockets, then proceeded to loot it, piling their booty onto military jeeps.

Units of the mainly Shiite 6th Brigade of the Lebanese Army, which has been loyal to Berri, were withdrawn to their barracks at dawn after failing to stop the fighting.