President Bush teased his ambassador in Baghdad by giving him the nickname "Sunshine," because of his sometimes-gloomy assessments of the political situation there. But Ryan Crocker persisted down to the last days in describing things precisely as he saw them.

Journalists probably shouldn't have heroes, but Crocker is one of mine. We first met in 1981 in Lebanon, and I've watched over the years as he took on the toughest challenges in the Foreign Service and became a superstar diplomat without ever losing his mordant sense of humor or his determination to speak truth to power. Crocker is leaving Baghdad and retiring from the Foreign Service next month, and he agreed (characteristically, with a grumble) to sit for a farewell interview last week while he was in Washington.

What made Crocker so unusual was his raw curiosity about the world. In the summer of 1970, when he was a student at Whitman College and determined not to spend the rest of his life in Walla Walla, Wash., he hitchhiked from Amsterdam to Calcutta. Traveling across the vast arc of the Middle East, he developed a fascination that never left him.

Crocker joined the State Department in 1971. He served in Iran and Qatar and then spent two years at a language school in Tunis, where he acquired his fluent Arabic. In 1981 he was sent to Lebanon as a political counselor, an assignment that shaped his career. He was in West Beirut when Israel invaded in June 1982; he was there three months later when the Sabra-Shatila massacre took place, courageously entering the camps and providing the first credible, official report of the slaughter; and he was there in April 1983 when a car bomb destroyed the embassy while he was inside.

The lessons of Lebanon stayed with Crocker, and they framed his view of Iraq. "Major traumas have very far-reaching consequences," he says. "The Israeli invasion of 1982 had a fundamental and ongoing impact on the entire region, and on us. It brought into being the Syria-Iran alliance, it brought into being Hezbollah -- and all the second- and third-order consequences, some of which we're arguably confronting today in Gaza."

Crocker's innate skepticism made him wary of Bush's decision to invade Iraq. He won't talk about his policy views, even now, except to say: "It was all opaque to me. I couldn't see what would happen." But he argues: "It doesn't matter what I or anyone else thinks about the wisdom of going in 2003. It's a distraction. We're in. We've been in for six years. . . . The focus has to be on where we go now."

Crocker arrived as ambassador in Baghdad in March 2007. Bush had already decided on a surge of additional U.S. troops there, but Crocker remembers wondering in the early days, "How on earth are we going to make this a better place?" A virtuous cycle slowly took hold: Newly confident Sunni Muslims began fighting al-Qaeda; Shiites decided they didn't need protection from the death squads of the Mahdi Army; and finally all the major Iraqi parties came together to endorse Crocker's appeal for a status-of-forces agreement and the gradual withdrawal of U.S. troops.

The key to success in Iraq, insists Crocker, was the psychological impact of Bush's decision to add troops. "In the teeth of ferociously negative popular opinion, in the face of a lot of well-reasoned advice to the contrary, he said he was going forward, not backward."

Bush's decision rocked America's adversaries, says Crocker: "The lesson they had learned from Lebanon was, 'Stick it to the Americans, make them feel the pain, and they won't have the stomach to stick it out.' That assumption was challenged by the surge."

Soon, Iraq will be Barack Obama's problem. And I ask Crocker what mistakes the new administration could make. He answers that he thinks it will avoid these errors, but he lists them anyway: "Concluding that this was the Bush administration's war, that it's stable enough now, that we don't want to inherit it, so we're going to back away."

Most of all, says Crocker, policymakers need to understand that this is a long game. A lasting change in Iraq isn't an on-off switch: "Not this year, not in five years, maybe not in 10 years."

The overarching lesson, he says, not just of Iraq but of his entire career, is that events have consequences that cannot be predicted, or escaped: "When we are part of a sweeping and traumatic set of events, we've got to understand that currents are set in motion that will play themselves out for many years, in ways that we can't always understand."

The writer is co-host of PostGlobal, an online discussion of international issues. His e-mail address is davidignatius@washpost.com.