In the months before his death by an assassin’s bullets on Tuesday, Ahmed Wali Karzai had quietly rebuilt his relationship with the United States and emerged as the most influential ally for American commanders and diplomats seeking to quell the Taliban insurgency in southern Afghanistan.

U.S. officials believed that Karzai, President Hamid Karzai’s half brother, had started to evolve this year from a self-interested strongman to a regional leader willing to take steps to share power with political and tribal rivals.

Karzai’s killing now poses a significant setback for the U.S. mission in Afghanistan. American officials had been hoping that his newfound willingness to embrace a U.S.-backed village defense program and the reintegration of Taliban fighters would help to cement recent improvements in security across Kandahar province.

In Kabul, senior military officials had remained more skeptical of Karzai than top commanders in the south, because of concerns that Karzai’s greed made him an unreliable and potentially damaging partner. Rather than criticize him publicly, U.S. officials expressed their skepticism about Karzai’s motives privately to senior Afghan counterparts. But they also had come to believe that they had little choice but to work with him.

One civilian adviser to the U.S.-led NATO military command said Karzai “had a very sophisticated and meaningful vision that pointed to what was needed politically to capitalize on the military gains.” The adviser and other sources spoke on the condition of anonymity to comment candidly about sensitive issues.

In recent months, the adviser said, Karzai had taken his leadership of the Kandahar provincial council far more seriously than he once did, turning it into “a growing political center of gravity that was resolving disputes.”

He traveled to insurgent strongholds with U.S. commanders to encourage residents to support a program that is a key element of the American strategy in Afghanistan: the training of armed villagers to defend their territory. And he was largely responsible for appointing a member of the Ghilzai tribe, a traditionally disenfranchised group that has been sympathetic to the Taliban, as deputy provincial governor.

“He may have been wanting to make a lot of money before, but he seems to be wanting to make his future here, and it changed fundamentally how he’s dealing with the Afghans and us,” a U.S. military official said less than 24 hours before Karzai was killed by a trusted confidant acting on motives that remained unclear.

Over the past six months, U.S. commanders and diplomats had met with Karzai regularly, traveled with him to remote parts of the province and consulted him for guidance.

“It was very useful to have access to his political advice and insight on Kandahar politics,” a civilian U.S. official said.

Karzai’s new attitude also extended to a more open engagement with journalists: He was killed an hour before he was to have lunch at his home with a Washington Post reporter.

Earlier this summer, a delegation of 170 tribal elders and prominent Kandaharis traveled to Kabul to ask President Karzai to appoint Ahmed Wali Karzai as Kandahar’s governor. Although the participants appear to have had varying reasons for doing so, U.S. and NATO officials believe it was an indication of how Ahmed Wali Karzai had managed to improve his relations with Kandahar’s disparate and rival tribes, emerging as the most powerful man in the province. The group even included the brother of the Karzai family’s principal competitor for influence in the south, former Kandahar governor Gul Agha Sherzai.

“It wasn’t contrived,” the civilian adviser said. “It was authentic.”

Karzai’s death, the adviser said, will be perhaps the most wrenching test of the resiliency of the Afghan government. “How long will it take for them to recover from this? And what does that do to our plans?”

The recent shift in the U.S. relationship with Karzai was a full circle of sorts. Through late 2008, he was viewed as a valuable source of intelligence about Taliban activity, and his cooperation was rewarded with payments from the CIA, according to U.S. officials. All the while, he sought to amass power — both economic and political — to fend off a host of rivals, including Sherzai.

Western intelligence officials believe he and his associates profited handsomely from construction and private-security contracts to support the growing international military presence in the south.

By mid-2009, several influential U.S. military and civilian officials wanted Karzai to be sacked as provincial council leader because of allegations that he was corrupt and involved in drug smuggling. He was also accused of helping to stuff ballot boxes in favor of his brother in that year’s presidential election.

In 2010, after failing to uncover clear-cut evidence of wrongdoing, the United States switched course. Diplomats and military officers sought to constrain him. They set down red lines that they warned him not to cross, including an admonition not to meddle in parliamentary elections. He largely complied, U.S. officials said, but he remained a tainted figure and was not openly embraced.

This year, the relationship changed again. Leaders of the U.S. Army’s 10th Mountain Division took over command at the NATO headquarters in southern Afghanistan, and they set out to more actively engage with Karzai, who also served as the president’s representative to southern Afghanistan.

U.S. officials believe that overture, coupled with two other factors — significant improvements in security across the south and encouragement from relatives — led him to change course. “He concluded that this was perhaps the last, best opportunity to build a new Afghanistan,” the civilian U.S. official said.

Some U.S. military strategists and analysts in Kabul and Washington take a different view, questioning the extent and sincerity of his transformation. They say Karzai remained a divisive figure in Kandahar, and they believe his death could accelerate the stabilization of southern Afghanistan.

But military and civilian officials in southern Afghanistan surmised that as the war effort has evolved, he concluded that his interests would be best served by pursuing a new style of leadership that was more in sync with U.S. and NATO objectives — that sharing some power now would pay off in the future.

The civilian official called him “a tenacious defender of personal and family interests,” but of late, there was “an overlap between his interests and those of the people and the province.”

Karzai’s death now creates a power vacuum in the most important province for the U.S. military campaign. It also leaves the president’s tribe, the Popalzai, without a leader.

U.S. officials fear the selection of successors for the council and tribal posts could be a protracted, potentially destabilizing process that the Taliban could exploit. The killing will almost certainly set in motion a series of events that will complicate the U.S. mission.

“This was a strategic strike,” the military adviser said. “Those who are celebrating are making a mistake.”

Staff writer Greg Jaffe in Washington contributed to this report.