U.S. forces withdrew overnight from the headquarters here of Shiite Muslim fighters that they had taken only days before, leaving the areas around two major shrines firmly in the hands of the insurgents.

Earlier, on Thursday in Baghdad, U.S. military officers said that they would open an investigation into a ground and air assault in western Iraq that has produced sharply conflicting accounts of whether the approximately 40 people killed were mostly foreign insurgents or civilians celebrating a wedding.

Overnight in Karbala, rebels loyal to the Shiite cleric Moqtada Sadr fired rocket-propelled grenades and automatic weapons on a company of U.S. troops as they withdrew from the mosque. There were no American casualties.

U.S. Apache helicopters fired on rebel attackers as troops wound out of the center of the city. Capt. Noel Gorospe, a spokesman for the 1st Armored Division's Task Force 1-37, said the withdrawal from the mosque does not mean retreat from the city. "We are certainly not pulling out of Karbala. We will continue to do normal operations," he said. Gorospe said U.S. forces will take measures to keep Sadr's militia, the Mahdi Army, from reoccupying the Mukhaiyam Mosque, which it had used as a major operations center and weapons depot.

For several weeks, U.S. military commanders said U.S. forces here and in other cities expected to chip away at the Mahdi Army and isolate Sadr in Najaf. They had hoped that Shiite religious and political leaders who cooperate with occupation forces would persuade Sadr to give himself up and disband his militia. Sadr is wanted by the United States for the murder last year of a moderate Shiite cleric.

Sadr has refused to surrender and his forces, despite absorbing more than 100 fatalities in Karbala and scores of others elsewhere, have held on. "They have shown a remarkable willingness to die," said Col. Peter Mansoor, commander of the 1st Brigade, 1st Armored Division.

Witnesses near the village of Makr al-Deeb, in the desert near the Syrian border, told television crews that a U.S. military aircraft strafed innocent people, mostly women and children, at a wedding party. U.S. military officers, however, maintained for a second day Thursday that the target was a way station used by armed foreign insurgents who cross the porous border into Iraq.

"How many people go into the middle of the desert 10 miles from the Syrian border to hold a wedding 80 miles from the nearest civilization?" asked Maj. Gen. James N. Mattis, commander of the 1st Marine Division, which operates in western Iraq. "Let's not be naive."

The dead included "more than two dozen military-age males," Mattis said at a news conference in Fallujah.

On Thursday, the Associated Press quoted people who identified themselves as survivors saying that the attack was directed at a wedding party of the Bou Fahad tribe, a group whose members often herd animals into the desert to graze.

By this account, about 25 men had come from the town of Ramadi for the celebration. A band was playing tribal music Tuesday night when airplanes were heard circling overhead. Out of fear, the celebration was called off. Many of the men retired to a tent to sleep, and women and small children went to a stone house.

The first bomb struck the tent at about 2:45 a.m. Wednesday, people told the news service. Among the dead was Hussein Ali, a popular wedding singer. A second bomb struck the house, killing everyone inside. Two helicopters landed, and about 40 troops searched the area, taking money and jewelry that guests had brought, and blowing up a pair of houses.

The people denied that fighters were in the area, the Associated Press reported.

In a telephone interview, an Iraqi Health Ministry official said a hospital in Qaim, the town closest to the site, reported that 42 people were killed -- 17 men, 11 women and 14 children. One man, four women and four children were wounded, the official said on condition of anonymity. The senior military spokesman in Iraq, Army Brig. Gen. Mark Kimmitt, said an investigation was "the only prudent thing to do" because of the seriousness of the allegations. TV footage from the scene Wednesday showed several bodies, including those of children, being unloaded from a truck and villagers digging dirt graves.

The dead included 34 to 35 men and "less than a handful of women," Kimmitt said at a news conference in Baghdad. U.S. ground troops stayed at the site "for an extensive period of time," he said, and did not find any dead children among the casualties.

Kimmitt said the number of men killed compared with the number of women killed appeared inconsistent with the makeup of a wedding party. He also said the time of the attack, around 3 a.m., was "kind of an odd time to be having a wedding."

Kimmitt said ground forces were attacked and returned fire. He did not directly answer a question about whether foreign fighters were the only people killed.

"At this point, the intelligence that we have and the intelligence that we drew on to conduct this operation was sufficient for us to believe -- to conduct that operation," he said. "We believe that we operated within the rules of engagement for that operation."

"This is one of those routes that we have watched for a long period of time as a place where foreign fighters and smugglers come into this country," Kimmitt said. He added: "We are satisfied at this point that the intelligence that led us there was validated by what we found on the ground, and it was not that there was a wedding party going on."

The strike was conducted by an Air Force Special Operations AC-130 gunship, which carries machine guns, cannons and a 105mm howitzer, according to a Pentagon official who spoke on condition of anonymity.

Ground forces at the site found AK-47 rifles, sniper rifles, shotguns, handguns and machine guns, along with foreign passports, satellite communication equipment and roughly $1,000 in Iraqi dinars, Kimmitt said.

Kimmitt characterized the people at the site as "town dwellers" rather than Bedouin desert inhabitants and said that four-wheel-drive vehicles and jewelry were also found at the site.

In a separate development, the military announced that two soldiers were killed in combat.

In one incident, a soldier was killed and three were wounded when their unit was attacked with hand grenades early Wednesday in central Baghdad.

A 1st Infantry Division soldier was killed Wednesday afternoon and another was wounded by a roadside bomb and gunfire near the northern town of Samarra. A third soldier was slightly injured while trying to put out a fire caused by the explosion. Three suspected attackers were wounded when the soldiers returned fire. Two of the suspects were detained, and the third escaped.

Chan reported from Baghdad. Staff writer Thomas E. Ricks in Washington contributed to this report.

Mourners carry the coffins of Hussein Ali, a popular wedding singer, and his brother in Baghdad. Iraqis say they were killed when U.S. forces bombed a party.Mahdi Nawaf shows photos of family members he says were killed in an assault that U.S. officials insist targeted a way station used by insurgents.