This article was written by Mark Mazzetti, Ashley Parker, Jane Perlez and Eric Schmitt.

WASHINGTON  The American arrested in Pakistan after shooting two men at a crowded traffic stop was part of a covert, C.I.A.-led team collecting intelligence and conducting surveillance on militant groups deep inside the country, according to American government officials.

Working from a safe house in the eastern city of Lahore, the detained American contractor, Raymond A. Davis, a retired Special Forces soldier, carried out scouting and other reconnaissance missions as a security officer for the Central Intelligence Agency case officers and technical experts doing the operations, the officials said.

Mr. Davis’s arrest and detention last month, which came after what American officials have described as a botched robbery attempt, have inadvertently pulled back the curtain on a web of covert American operations inside Pakistan, part of a secret war run by the C.I.A.

The episode has exacerbated already frayed relations between the American intelligence agency and its Pakistani counterpart, created a political dilemma for the weak, pro-American Pakistani government, and further threatened the stability of the country, which has the world’s fastest growing nuclear arsenal.