The Central Intelligence Agency, working with American troops during the occupation of Iraq, repeatedly purchased nerve-agent rockets from a secretive Iraqi seller, part of a previously undisclosed effort to ensure that old chemical weapons remaining in Iraq did not fall into the hands of terrorists or militant groups, according to current and former American officials.

The extraordinary arms purchase plan, known as Operation Avarice, began in 2005 and continued into 2006, and the American military deemed it a nonproliferation success. It led to the United States’ acquiring and destroying at least 400 Borak rockets, one of the internationally condemned chemical weapons that Saddam Hussein’s Baathist government manufactured in the 1980s but that were not accounted for by United Nations inspections mandated after the 1991 Persian Gulf war.

The effort was run out of the C.I.A. station in Baghdad in collaboration with the Army’s 203rd Military Intelligence Battalion and teams of chemical-defense and explosive ordnance disposal troops, officials and veterans of the units said. Many rockets were in poor condition and some were empty or held a nonlethal liquid, the officials said. But others contained the nerve agent sarin, which analysis showed to be purer than the intelligence community had expected given the age of the stock.

A New York Times investigation published in October found that the military had recovered thousands of old chemical warheads and shells in Iraq and that Americans and Iraqis had been wounded by them, but the government kept much of this information secret, from the public and troops alike.