The writer, a lieutenant colonel in the U.S. Army, was a combat adviser in Iraq in 2011. The views expressed are his own and do not represent the position of the U.S. government.

Two days before the U.S. military mission in Iraq formally ended in 2011, I left with the last convoy of Americans from Contingency Operating Site Kalsu, south of Baghdad. Safely crossing the border into Kuwait meant that we had accomplished our most important mission: getting out of the country alive, without any strategic blunders. If the U.S. troops in Afghanistan also can attain this goal, which will not be easy, they will have achieved the best we can hope for in that country.

Now, as in the last days of Iraq, U.S. hopes are muted. Previous aspirations for democracy and freedom have shrunk, and most of us will be happy if the United States can extricate itself quietly without further damage or embarrassment. The cornerstone of the plan to exit Iraq was the training of Iraqi police and military forces, enabling them to create a safe environment during and after our departure. It’s the centerpiece of operations in Afghanistan, as well.

As the months march toward the end of the major U.S. military presence in Afghanistan, the stresses on units will grow. Life becomes increasingly austere at the end: creature comforts vanish, food quality worsens, mail stops. Tactically, the focus alters. Yesterday’s top priorities — defeating the enemy, building up the indigenous forces — become less important than leaving with each soldier safe. It becomes clearer by the day that, barring some deus ex machina, the U.S. endeavor will make no strategically significant gains, though the potential for significant losses increases by the week.

As troop densities diminish, soldiers take on new tasks, each of which constitutes a distraction from combat missions. Accounting for the detritus accumulated through a decade of war is not simple, nor is packing up and preparing for departure. As a result of these tasks, gradually decreasing combat power and the desire to avoid rankling local civilians, soldiers will confine their patrols to areas close to the base and directly linked to U.S. force protection. Challenges will increase toward the end, as surveillance equipment, interpreters and weapons systems disappear. U.S. units will need to transfer security responsibilities to Afghans as we did to Iraqis and they will need to pray those forces hold their ground.

If the situation in Afghanistan mirrors ours in 2011 Iraq, U.S. troops will find themselves in a quickly changing relationship with their host nation. For years, the Iraqi security forces were the recipients of U.S. largesse, which both outfitted them with needed equipment and supplies and obligated them to support the U.S. mission. The situation changes as the flow of materiel slows. At some point, U.S. forces in Afghanistan will have no more to give their counterparts, and it will be time for the Afghan national security forces to work through their own systems for repair parts, construction materials and medicine. The Afghans, like the Iraqis, will do without some vital provisions. And they will no longer be compelled by their reliance on us to cooperate.

Goodwill and trust became the keys to our survival in Iraq, and they will be central again in the withdrawal from Afghanistan. We met regularly with the Iraqi generals in charge of the province’s police and army capabilities, and their subordinate elements worked with our patrols daily. At the same time, our Iraqi partners began to distance themselves from us. Some had long-standing familial or ideological ties with our enemies. Even our friends no doubt saw that closeness with us — which previously had been the ticket to significant benefits — might become a liability after our departure.

Therefore, we did not wholly trust the Iraqi security forces. We well understood that the last moments at Kalsu would be the most dangerous, so when our Iraqi partners inquired about our departure plans, we temporized. Our small deceptions hid the details from our friends. One example: We challenged the Iraqi forces to a soccer tournament at Kalsu, and even bought soccer uniforms and a trophy from an Iraqi vendor. By the tournament date, of course, we were in Kuwait.

This sort of paradoxical arrangement will color the last months in Afghanistan. U.S. units will increasingly rely for their safety on their Afghan counterparts but will not completely trust them. In Iraq, our course of cautious reliance proved successful.

As we left Iraq in 2011, we worried about the Iraqis’ dependability. Were they proficient enough to prevent attacks? Were they committed enough to want to? The recent spate of green-on-blue violence in Afghanistan complicates an already complex relationship between Afghan national security forces and Americans. The challenge for U.S. forces will be to navigate between trust and distrust of Afghans so their transition, like ours more than a year ago, will be uneventful.

The best outcome for the U.S. departure from Afghanistan? A safe exodus and a slow news day.