KARACHI, Pakistan - Pakistan freed an FBI agent on nearly $10,000 bail three days after he was detained carrying knives and ammunition in his bag, officials said, a relatively quick release that was likely to prevent the situation from escalating into a diplomatic spat.

The arrest of the American, identified as Joel Cox from the bureau's Miami field office, came amid thawing relations between a new Pakistani government dependent on aid and a U.S. administration that needs Islamabad to help contain militancy on the border with Afghanistan.

The two countries, which have been uneasy allies since the 9/11 attacks, have seen ties strained over a series of incidents. CIA contractor Raymond Davis shot and killed two Pakistani men in Lahore in January 2011. The U.S. unilaterally killed Osama bin Laden in the Pakistani city of Abbottabad in May 2011, and American forces accidentally killed 24 Pakistani troops along the Afghan border the same year. U.S. drone strikes in the country also have angered Pakistanis.

But Prime Minister Nawaz Sharif, who took office in June, and President Obama have moved to ease tensions. The United States has released more than $1.6 billion in military and economic aid to Pakistan that was suspended in 2011.