Militant fighters of the Islamic State mounted one of their fiercest assaults in months on Wednesday, setting off 21 car bombs in the city of Ramadi, even as the group lost ground in an Iraqi government offensive in Tikrit, security officials said.
Security forces fought Islamic State holdouts in two remaining neighborhoods on the west side of Tikrit, the birthplace of Saddam Hussein, where militants massacred more than 1,000 Shiite Iraqi soldiers last year.
The city has been the focus of a weeklong assault by Iraqi forces, the largest operation against the Islamic State, also known as ISIS or ISIL, since it swept into control of much of the country last year. Iraqi government troops and their Shiite militia allies appeared to be close to recapturing the city on Wednesday and scoring a strategically and emotionally significant victory.
To the west, in Ramadi, the capital of Anbar Province, the militants aimed to show that they could still inflict pain even as they lost ground in Tikrit.
Hikmat Suleiman, the political adviser to the governor of Anbar, said that because of fortified defenses, growing battle experience and improved intelligence, the Iraqi forces in Ramadi were able to keep casualties in the car bombings to a minimum by attacking and thwarting the vehicles as they approached, blowing up most of them before they reached their apparent targets.
A senior military official at the Anbar Province operations command said five people were killed in the bombings and scores were wounded.
With so much attention focused on Tikrit, the fighting in Anbar has raged largely out of the spotlight, but it has been fierce. Two top commanders on the government side were killed as the security forces came close to retaking the town of Garma from militant control.
Iraqi leaders attending an annual forum in Sulaimaniya, in the semiautonomous Kurdistan region, followed the news of the battles with great interest on Wednesday, declaring in speech after speech that the highest stakes and biggest challenges would come after the Islamic State was defeated in Tikrit and elsewhere, and the time came to unify Iraq.
Much rides on the outcome of the battles and what happens afterward. The bulk of the government forces are made up of Shiite militias, and there have been fears that they would engage in revenge attacks in Tikrit and Anbar, as they have been accused of doing in Diyala Province.
Even so, some Sunni residents in areas held by the Islamic State have said that they would welcome the Shiite militias if they rid them of the militants’ harsh rule. Community leaders said that a victory without abuses in its wake could help reduce tensions between the sects.
A video circulating on social media appeared to have been taken by government-allied militiamen as they drove through Albu Ajeel, a town south of Tikrit. Rows of burning buildings are seen, and a uniformed man by the side of the road is heard to say, “Burn them, burn them.” The person who is apparently doing the filming is heard saying that the Asa’ab Ahl al-Haq militia is in control of the town.
Many Shiite militiamen believe that the residents of Albu Ajeel took part in the massacre of the soldiers last year, and some Iraqi commentators said on Wednesday that the video was evidence that the militias were carrying out revenge attacks.
But in Alam, another town near Tikrit were buildings were set on fire on Wednesday, the mayor, Laith Hameed al-Jabouri, said the Islamic State militants were responsible. He said in a telephone interview that he had entered the town along with local Sunni fighters and Shiite militia forces, and found that the buildings, including his house, were already on fire.
“Would I burn my own house?” he said.
At least 4,000 Sunni tribal fighters have taken part in the battle for Tikrit on the government side, and another 4,000 have been mobilized in Anbar, according to security and provincial officials.
In Anbar, Shiite militias have only a minimal presence, according to Mr. Suleiman, the political adviser. He said most of the fighting there was being carried out by the official Iraqi armed forces and local fighters, including what is known as an Awakening brigade, composed of Sunni Arabs who oppose the Islamic State.
Awaad Sami al-Laghawa, the leader of the brigade, was killed in battle on Tuesday, officials said, along with the assistant commander of an Iraqi army division, Brig. Gen. Wadha Mahmood Al-Azzawi.
Northeast of Tikrit, security forces, local Shiite militias and Sunni tribal fighters took over an Islamic State camp in the Hamrin hills and freed 34 hostages from the Obadi and Masari tribes, officials said.
The security forces also retook a police station, a gypsum factory and the oil fields at Ajeel and Aas, while militant fighters retreated toward the town of Hawija.
“We will not stop until we liberate Hawija and raise the flags over it,” said Sheikh Hatim Al-Assi, a spokesman for the local fighters, adding that the tribal force would also help in the larger battle for Mosul.
“We will take revenge on the killers and the criminals,” he said. “ISIS has no place in our society, and we are one hand with the army and the mobilization fighters and the peshmerga to eliminate them.” Mobilization fighters refers to the Shiite militias, and the peshmerga are Kurds.
Mr. Al-Assi said residents in Hawija had reported that the militants were preparing to abandon the town and evacuate their families to Mosul or across the border into Syria.
“They are leaving everything behind them, and stealing everything, and they are being defeated, so their staying here means their death,” he said. “We will not have mercy on those who killed and stole and displaced and abused our people.”
In Tikrit, security officials said government troops were still trying on Wednesday afternoon to take control of Saddam Hussein’s former palaces on the Tigris riverbank, the scene of the massacre. There was no more shooting coming from the palaces, they said, but the troops were proceeding cautiously in securing the grounds because of the risk of roadside bombs and booby traps.