BZEIBEZ BRIDGE, Iraq—As throngs of Iraqis fled the Islamic State takeover of Ramadi across this bridge to Baghdad, the men among them were met with a surprising order from a military official: Stay back and fight the extremists.

“Women, children, you are free to pass. Young men, you must return to defend your land,” a Baghdad military official called out on a megaphone to thousands waiting to cross recently, according to policeman Fahd Bassem who was stationed there at the time.

The order from the Shiite-led central government was jarring, said some of the Sunni residents of Anbar province who tried to escape over the past two weeks. Thousands of Sunni tribal fighters were already battling Islamic State in Ramadi, the provincial capital, and the surrounding area. And thousands more Iraqi soldiers and Shiite paramilitary fighters have converged for a counteroffensive on the city and other parts of the province—the heartland of Iraq’s aggrieved Sunni minority.

“We do not want to encourage young, able men who can fight Daesh to emigrate,” said Saad Maan, an interior ministry spokesman, using an Arabic acronym for Islamic State. “They say they are coming out to accompany and protect their families. This is not a good enough excuse.”

On the outskirts of the capital and 50 miles southeast of Ramadi, Bzeibez is the only crossing over the Euphrates river between Anbar and the capital Baghdad. For five days after Ramadi fell to the Sunni extremists of Islamic State on May 17, the bridge was either completely or intermittently closed to those fleeing violence, officials at the bridge and in Baghdad said.