July saw the beginning of the end of the Islamic State. Iraqi Security Forces along with the Kurdish Peshmerga, and Popular Mobilization Units liberated Mosul in Iraq, and freedom is imminent in Raqqa, Syria.

Unfortunately, despite years of advanced planning, Baghdad is facing the same catastrophe the United States faced in 2003 with no day-after plan. Instead of earning legitimacy through reputation, the Baghdad government now competes with more than 30 other groups to provide basic services in post-ISIS Mosul.

In 2014, Moslawis only had to choose between the marginally lesser of two evils, and ISIS offered property rights along with other standards of law and order citizens expect from the government. ISIS posted a social contract known as "documents of the city" in occupied territories that included the right to private property, the right to protection from arbitrary arrest, and an appeals process that even high-level officials had to go through. In the beginning, that order attracted many of the 500,000 Moslawis who initially fled to return to ISIS-occupied Mosul.

Today, their options are not much better.

Even in the rally to reclaim ISIS territories, Iraqis, mostly Shiites and even minority groups such as Sunnis, Christians and Yazidis felt more comfortable joining the PMU rather than the official army, which many criticized as former prime minister Nouri Al Maliki's personal militia.

Besides sorting out governance, several other complicating factors remain unresolved, such as what to do with ISIS conspirators. It is yet to be seen if ISIS as an organization will transition into an insurgency or if true believers will don civilian garb and compete for votes. The same question remains for all the other militias that cooperated in their defeat.

One answer comes from Peru.

In the 1980s, the country faced a rapidly-expanding Marxist insurgency. The Sendero Luminoso movement claimed the lives of 70,000 and the U.S. State Department warned Peru would witness a Khmer Rouge-type genocide.

Twelve years later, it ended. Its leader, Abimael Guzman, was found unprotected and disheveled much like Iraq's late Saddam Hussein. Once a god-like figure, he now rots in prison mostly forgotten, and those that carry on the name of his movement are regarded as nothing more than common drug smugglers.

An ideal defeat for Abu Bakr and his thugs.

Guzman credits his defeat not to bullets and bombs, but to Peruvian economist Hernando De Soto and his think tank, the Institute for Liberty and Democracy.

Like Iraq, the Peruvian countryside responded to the Sendero threat by creating their own militias. The Lima government, at first, saw all as enemies. The peasant forces were extra-legal and predominantly coca farmers. De Soto worked to change this mindset by differentiating the farmers from drug traffickers, explaining that their informal legal status left them with limited options. They needed another way.

According to De Soto, the basis of his plan was to "harness the surge of bottom up enthusiasm for property rights and political independence by documenting groups and their property and substituting terrorist enforcement with the rule of law." The peasant army became formally recognized as an ally of Lima. Then, in no small feat, formal property titles were issued to those in the informal economy. Title registration rose eight-fold, the number of legal business increased 15 times, and $8 billion was added to the economy in one year alone. Families for the first time could access formal banking systems for loans and use courts to settle disputes. Sendero supporters lost their grievances against the state.

Baghdad is on the right path: The PMU has already been formally incorporated into the Iraqi army, and others must follow. Al-Abadi must continue to free himself from Maliki's reputation and create the legal and political environment to win the trust of post-ISIS Iraq and the international community. The last ingredient needed is a large influx of reconstruction capital, billions of dollars, that will certainly not come from the U.S. unless Baghdad can ensure it will be spent on necessities and not ghost soldiers.

Failure to establish a good governance track record will certainly leave the political vacuum open, and condemn the region to a failed state status much like 1990s Somalia.

Philip Thompson is a fellow with the Property Rights Alliance, an affiliate of Americans for Tax Reform.

If you would like to write an op-ed for the Washington Examiner, please read our guidelines on submissions here.