An Iraqi elite forces soldier stands atop a Humvee in the village of Bazwaya. (Marko Drobnjakovic/AP)

Despite suicide attacks, snipers and roadside bombs, Iraqi commandos swept into the eastern edge of Mosul on Tuesday, setting foot in the city for the first time since it was seized by Islamic State militants more than two years ago.

It was a rapid and symbolic incursion into the northern Iraqi city at the heart of the militant group’s self-proclaimed “caliphate.” But bringing the fight into Mosul’s limits does not change the overall challenges facing Iraqi troops trying to oust the militants from their last major stronghold in Iraq. Ahead lie booby-trapped defense lines, networks of tunnels and neighborhoods packed with civilians.

Explosions and heavy exchanges of gunfire could be heard from Mosul’s Gogjali district as Iraq’s elite counterterrorism forces battled to retake it Tuesday. Jets streaked overhead.

Iraqi commanders and U.S. officials say they can only guess how hard the militants will fight for the city, the most populous that the Islamic State controls.

While it is central to the group’s state-building aspirations, it is also a prize the militants appear likely to lose. Tens of thousands of Iraqi and Kurdish troops have closed in since the launch of an ambitious offensive just over two weeks ago, backed by air and artillery strikes by a U.S.-led coalition. More than 1 million civilians are said to remain in Mosul, and the militants have kidnapped the people of entire villages on the city’s outskirts to use as human shields, say those who have escaped.

“There was desperate resistance by the enemy,” said Lt. Gen. Abdelwahab al-Saedi, a commander with Iraq’s counterterrorism forces. By the end of the day, Gogjali had largely been secured, although mines, explosives and some “pockets” of resistance were still being cleared, he said.

The elite forces were building on their momentum and moving deeper into Mosul, fighting on the edge of neighborhoods farther west, he added. The 9th Armored Division of the Iraqi army also said it had reached the city’s edge.

The speed of the gains, however, appeared to come at the expense of thorough operations to secure and clear territory as government forces advanced.

The elite Iraqi troops are making a sharp push into Mosul from the east. But forces on other fronts remain farther away, exposing advancing troops to attack from their flanks as they attempt to press forward. The militants’ extensive network of tunnels allows them to evade airstrikes and launch surprise attacks.

On the outskirts of the village of Bazwaya — about four miles east of Tuesday’s main clashes — the crack of gunfire sent journalists and Iraqi forces running for cover. “Enemy fire!” shouted one soldier, as bullets pinged off the metal shutters of a deserted row of shops where they had been camped out.

The troops fired back with machine guns and later said they found and killed three armed militants holed up in a building.

The complex military battle to retake Mosul from the Islamic State has begun. Here is what you need to know about the ancient Iraqi city. (Ishaan Tharoor, Kareem Fahim, Jason Aldag/The Washington Post)

“There are still sleeper cells around in the villages,” said one Iraqi captain who spoke on the condition of anonymity because he was not authorized to address the media. “There are some gaps in our control, and they are using their tunnels.”

Earlier in the day, the militants sent a military vehicle packed with explosives to the village, leaving a gaping crater in the road. The sand-colored Humvee was flying the Iraqi flag in an attempt to look like a friendly Iraqi army vehicle, soldiers said. “We knew it was the enemy as there are only counterterrorism forces here,” said 1st Lt. Baraa al-Sultani, noting that Humvees used by the elite forces are black. “We opened fire.”

With a fragile grip on some of the territory behind them, Lt. Gen. Abdul Ghani al-Asadi, commander of the counterterrorism units, said he would meet with army and tribal fighters later Tuesday to seek an agreement on sending forces to hold the ground as the elite units progress.

“We are going to advance farther, so we don’t want to be exposed,” he said.

So far, many of the areas retaken by Iraqi forces have been largely empty of civilians. Iraqi forces say their advance may slow as they near heavily populated areas of the city. A humanitarian crisis is feared if Mosul residents flee en masse, and civilians have been advised to stay in their homes.

But many inevitably are uprooted during the conflict, and some have been forced into the city at gunpoint by the militants. Early Tuesday, the Islamic State brought dozens of trucks and buses to attempt to transfer 25,000 civilians from the village of Hamam al-Ali into Mosul to use as shields, the Office of the U.N. High Commissioner for Human Rights said.

“We have grave concerns for the safety of these and the tens of thousands of other civilians who have reportedly been forcibly relocated by [the Islamic State] in the past two weeks,” said spokeswoman Ravina Shamdasani.

On the main road to the front lines, small convoys of civilians could be seen leaving the surrounding area, holding white flags out of their car windows as they drove. Shepherds waving white flags herded their livestock out, as vehicles of the Iraqi elite forces sped in the other direction.

In Mosul, civilians were staying inside, according to Iraqis in touch with relatives there.

“They can hear the clashes and shooting and feel that the security forces are very close,” said one former Mosul resident who fled two years ago but spoke to family members in the city’s eastern Muthanna district on Tuesday. He declined to be named to protect his relatives from reprisals. “I cried when I spoke to them because I felt like I’m going to see them again soon.”

He said his relatives have mixed feelings about the advance, although they desperately want the militants to be ousted after more than two years of oppressive and fanatical Islamic State rule.

“They are happy, but they are afraid of airstrikes and afraid that Daesh will kidnap them and take them to another part of the city,” he said, using the Arabic acronym for the Islamic State.

William Booth in Irbil contributed to this report.