The US National Security Agency director has defended the spy agency saying that it was acting within legal boundaries.

His comments come amid a public uproar which has grown from anger over the collection of Americans' phone and email records to outrage over spying on European allies.

General Keith Alexander offered an impassioned defence of the beleaguered intelligence agency.

He told the House of Representatives Intelligence Committee that the NSA is focused on preventing attacks on Americans and allies, and operates under strict oversight.

Media reports in France, Spain and Italy that the NSA collected data on tens of millions of phone calls in those countries were deemed completely false.

Some of the data referenced in documents leaked by former NSA contractor Edward Snowden was collected not just by the NSA itself but was also provided to NSA by foreign partners, he said. 

He said that it represents information that we and our NATO allies have collected in defence of our countries and in support of military operations.

In response to a series of questions during a hearing before the House of Representatives Intelligence Committee, Director of National Intelligence James Clapper said spying on foreign leaders was a basic tenet of intelligence operations.   

Mr Clapper said: "We do not spy on anyone apart from valid foreign intelligence purposes and we only work within the law. 

"Now, to be sure on occasion we have made mistakes."

The intelligence chiefs are appearing against a backdrop of angry European allies accusing the United States of spying on their leaders and citizens.

Protesters in the hearing room held signs that said "stop spying on us" and yelled "lies, lies and more lies".

The intelligence chiefs appeared against a backdrop of angry European allies accusing the US of spying on their leaders and citizens.

The most prominent target appears to have been German Chancellor Angela Merkel, whose government said last week it had learned the US may have monitored her mobile phone.