When the Iraqi city of Ramadi fell to the Islamic State in May, the White House called it a “setback.” The administration’s many critics called it a disaster and proof that President Obama’s strategy to defeat the militants was failing.

Fast-forward seven months, and Iraqi security ­forces, backed by coalition air power, recaptured Ramadi this week. But even the administration itself has hesitated to call the victory a vindication or claim it as evidence that the militants are close to the destruction Obama has promised.

“Ramadi was a test of whether the Iraqi security forces­ were willing to fight” after their 2014 collapse in Mosul, Iraq’s second-
largest city, and later in Ramadi, a senior administration official said. This time, instead of running away, “they incurred huge losses­ and they didn’t flinch.”

“That’s why Ramadi was important,” the official said of the city about 80 miles west of Baghdad. “It’s not a turning point, but it’s an important milestone.”

Previous significant battles had been won largely by Kurdish ­forces, known as peshmerga, assisted by U.S. airstrikes, in the northern city of Sinjar in November or with Iranian-backed Shiite militias in the central city of Tikrit in March. This time, although U.S.-trained Sunni fighters are now moving into Ramadi to stabilize the area, the Iraqi army was largely alone on the ground.

Although the Ramadi victory has engendered at least modest optimism, there are far tougher battles ahead, including a much-delayed offensive to retake Mosul. That densely populated urban center in the north, with triple the population of Ramadi, has served as the Islamic State’s center of operations in Iraq since the militants overran it 18 months ago.

Islamic State fighters numbered in the hundreds in Ramadi; there are thousands in Mosul. Re­inforcements are expected from neighboring Syria, where efforts to dislodge the Islamic State have been hampered by an ongoing civil war.

More immediately, the Iraqi army is likely to turn its attention to Fallujah, just past the western outskirts of Baghdad, which the Islamic State has held for more than two years. “Compared to Ramadi, Fallujah is a lot smaller . . . and less populated,” said Col. Steve Warren, the Baghdad-based spokesman for coalition ­forces. “The flip side is that the population is much more sympathetic to this enemy,” as U.S. Marines discovered there more than a decade ago in what was later described as the heaviest urban combat they had encountered since the 1968 Battle of Hue in Vietnam.

The U.S. military attributes success in Ramadi to intensive Iraqi army training by U.S. coalition partners over the past year, the kind of slow but steady strategy that the administration says will ultimately prevail over the militants.

Skeptics note that the United States spent tens of billions of dollars rebuilding, training and equipping Iraqi security ­forces, whose dismantlement it ordered after the 2003 invasion, to apparently little long-term effect.

But that was the wrong kind of training for the current war, Warren countered. “The army that we built back in the mid-2000s and left behind was a counter­insurgency army,” he said. “An army like that is capable of conducting road clear­ances, checkpoint operations, [explo­sives] removal. . . . This enemy that they’re facing now is a conventional army, a proto-army. That’s something the Iraqi army wasn’t trained or equipped for in the first place.”

“What we’ve been doing for a full year is methodically, patiently rebuilding that army and re-equipping it to focus on the threat it now faces: . . . being able to put a bridge across a river . . . to get through a minefield . . . to integrate air power with land operations,” Warren said. “That’s a different kind of warfare.”

When Islamic State forces­ burst into Ramadi this past spring, it was with simultaneous explosions of massive truck bombs that terrified and intimidated the army and sent it running. “The Iraqi army wasn’t prepared for that weapon; it was something they hadn’t faced on the battlefield,” he said. “I’m not making ex­cuses for the army; they had plenty of other problems. But over the past seven or eight months . . . we equipped them to deal with it,” including supplying AT4 shoulder-launched anti­tank weapons and training the Iraqis to use them.

U.S. forces saw intelligence improvements, and pilots also learned how to better deal with the militants, their tactics and weapons, and to coordinate with the forces­ on the ground.

Many critics also attribute the army’s collapse last year to what the Senate Armed Services Committee chairman, John McCain (R-Ariz.), has called the “vacuum” created when Obama pulled out U.S. forces­ in 2011. The administration disputes the reasons for the withdrawal, and the ongoing influence the U.S. military might have had.

But officials agreed that the withdrawal allowed then-Prime Minister Nouri al-Maliki, a Shiite who valued sectarian dominance above competence, to complete his own gutting of the army’s Sunni commanders, some of whom joined the Islamic State.

Unity among Iraq’s various military forces­ will be crucial for future offen­sives. In Mosul, both the peshmerga and the Iraqi army — which are barely on speaking terms and fight separately — are expected to participate. Tribal fighters now moving into Ramadi are a separate force from the army, but they will be crucial in operations to clear and hold the Sunni heartland of Anbar province.

The current prime minister, Haider al-Abadi, also a Shiite, has given much lip service to inclusion but has made little headway in changing Iraq’s sectarian equation. “All these things have to move in harmony. . . . You can’t simply focus on the military and ignore political factors,” said the senior administration official, who spoke on the condition of anonymity to discuss internal assessments.

“Our diplomats are working day in and day out” on Iraqi political reconciliation, the official said, “but in some ways it is even more difficult. . . . These are existential questions that the Iraqis are asking themselves.”

“If there’s a lesson from the last year or so, it’s that if they’re not united, if they can’t overcome their political differences,” then whatever success they have against the Islamic State will be lost to the next extremist group taking advantage of their divisions, the official said.