-- The occasion was a groundbreaking ceremony for a U.S.-funded bridge, and U.S. Ambassador Zalmay Khalilzad rose to deliver his speech with the casual air of a man who has attended countless such events.

But toward the end of his remarks Saturday, the expression on the face of the gregarious, Afghan-born diplomat became uncharacteristically grave. "The United States' commitment to Afghanistan remains unshakable," he said in Dari, stressing each word for emphasis as the Afghan president, Hamid Karzai, looked on.

It seemed an apt time to offer reassurances: On Monday, Khalilzad vacates the post from which he has exercised extraordinary influence over Afghanistan's development to take up the job of U.S. ambassador to Iraq.

He leaves behind a country that by his own description remains at "the fourth kilometer of its 10-kilometer journey" toward a stable democracy.

Three-and-a-half years after the extremist Islamic Taliban government was ousted from power, the country has its first democratically elected president, millions of Afghan girls are enrolled in school, and there are more than 20,000 members of an ethnically integrated national army.

But Khalilzad's departure also comes as Taliban fighters have launched a campaign of almost daily bombings and ambushes in the south and east, scaring aid workers from large swaths of the country and threatening to undermine parliamentary elections scheduled for September. Meanwhile, the ambassador's early policy of accommodating powerful regional warlords in the interest of stability is increasingly coming into question because of their role in Afghanistan's burgeoning heroin trade, which produced nearly 90 percent of the world's supply last year.

At a final news conference Thursday, Khalilzad -- dubbed "the viceroy" by Afghans -- expressed confidence that Afghanistan would succeed despite those challenges and said President Bush tapped him for the Iraq job because of "the belief that Afghanistan is on the right trajectory."

"The key thing is not the person of the ambassador," said Khalilzad, whose nominated successor, Ronald Newman, was an adviser to the previous ambassador to Iraq, John D. Negroponte. "The key is the strategic relationship . . . between the two countries."

Many Afghans are not convinced.

When word of Khalilzad's likely job change surfaced in April, the chief of Afghanistan's Supreme Court, Fazl Hadi Shinwari, sent a letter to Bush pleading with him to keep Khalilzad in his post until the parliamentary elections.

"No one else can work as he has been doing," Shinwari wrote.

And even some Afghans who complained that Khalilzad too often upstaged Karzai say they are sorry to see him go.

The burst of nostalgia is a testament to the unique combination of qualities Khalilzad brought to the assignment when he was first appointed U.S. envoy to Afghanistan in January 2002, and ambassador in November 2003.

A former university professor who has served in the State Department, the Pentagon and the National Security Council, Khalilzad had the connections and influence of a consummate Washington insider.

But his Afghan heritage and work supporting anti-Soviet fighters going back more than two decades afforded him a mastery in Afghan languages and tribal politics that few diplomats manage to acquire by the end of their tours.

Nader Nadery, a member of the Afghan Independent Human Rights Commission, recalled first seeing Khalilzad in action in 2001 at a conference in Bonn at which Afghanistan's disparate opposition groups hammered out a plan for an interim government.

"I thought, 'Wow, this guy is really capable of making people come to agreement,' " Nadery recalled. "It wasn't just that he could speak Dari or Pashto, but the way he could find the right words to sway the people between whom he was mediating."

In the years since, Khalilzad has used his negotiating skills to defuse numerous potential crises -- effectively forcing a Tajik warlord, Ismail Khan, to step down as governor of the western province of Herat last August after fighting broke out between Khan and a rival militia leader, for instance. More recently, he persuaded several losing candidates to drop their complaints of fraud in the October presidential election.

But Khalilzad also earned the resentment of various opposition figures, who complained that he had been too overt in supporting Karzai. Meanwhile, Khalilzad's high profile and energetic style often seemed to undermine the president's authority.

"Some of the pronouncements that he would make were things that you would expect to come from a government official, not a foreign representative," said Paul Fishstein, director of the Afghanistan Research and Evaluation Unit, a nonprofit research organization based in Kabul.

At the news conference Thursday, Khalilzad was unapologetic. "I'm here to help," he said. "I'm not a potted plant."

During a brief interview after the bridge ceremony on Saturday, however, he seemed more reflective on his early decision to allow warlords with checkered pasts, such as Khan -- who has been appointed energy minister since his ouster from the governorship of Herat -- and Gen. Abdurrashid Dostum, an Uzbek strongman, to play a role in the formation of the government.

"Of course, I retain the right to change my mind down the road," he said, laughing. But he said that "at this point in time," he still felt it was the right move.

"It allowed for disarmament and reintegration to move forward without it becoming very violent and requiring the use of force," he said, referring to an official disarmament program under which 99 percent of registered strongmen have given up their declared weapons.

Fishstein countered that many former militia leaders retain hidden stockpiles and have only grown in power through profits from the drug trade. "Whether you could have neutralized the warlords back then is not clear," he said. "But it's certainly going to be harder to neutralize them now."

Khalilzad stressed that Afghanistan's setbacks measured up well against the challenge of building a nation from such an ethnically diverse population after years of conflict.

"I'm not saying the process is completed," he said. "But we've done things in terms of achieving those goals that in other places have taken hundreds of years."

"The United States' commitment to Afghanistan remains unshakable," U.S. Ambassador Zalmay Khalilzad said.