Image caption M Khalifi was charged in a Virginia court on Friday afternoon

A man has been arrested near the US Capitol building as part of an anti-terror investigation, US officials say.

Amine El Khalifi, 29, is said to be an illegal immigrant originally from Morocco.

Officials said the man thought he was heading to carry out a suicide attack on the Washington DC building, home to the US Congress.

He was "closely and carefully monitored" for weeks, according to the FBI and US Capitol police.

Authorities say the public was never in any danger.

Mr Khalifi allegedly thought undercover FBI agents he was working with were members of the al-Qaeda network.

However, he was not believed to have any genuine connections to al-Qaeda, officials said.

Vest 'inoperable'

Mr Khalifi made a brief court appearance and was charged with attempting to use a weapon of mass destruction against US property - a charge that carries a maximum penalty of life in prison.

A bail hearing was set for Wednesday.

Image caption Mr Khalifi was arrested a few blocks from the Capitol building, reports said

The suspect was said to have overstayed a visitor visa since 1999, and was under investigation for more than a year. He was based in Alexandria, Virginia.

He carried a vest he thought was packed with explosives, reports said, but had in fact been supplied and made harmless by undercover agents. He was also carrying a gun that did not work.

"Explosives the suspect allegedly sought to use in connection with the plot had been rendered inoperable by law enforcement and posed no threat to the public," a spokesman for the US Justice Department said.

Mr Khalifi was said to have been arrested in a parking garage a few blocks from the Capitol as he made his way towards Capitol grounds. He had been under surveillance for several weeks.

According to an FBI affidavit, Mr Khalifi met other individuals at a residence in Arlington, Virginia in January 2011, at which he agreed with a statement that the "war on terrorism" was a "war on Muslims" and said the group had to be ready for war.

'Test bomb'

He considered other targets for an attack including an office building in Alexandria and a Washington restaurant, the affidavit said, before switching his sights to the Capitol.

It said he had detonated a test bomb in a quarry in West Virginia in the presence of undercover operatives last month.

He had also visited the Capitol on multiple occasions to plan the details of the alleged attack.

US law enforcement officials routinely carry out "sting" operations in an effort to stop potential terror suspects.

In one of the most recent incidents, in September 2011, 26-year-old US citizen Rezwan Ferdaus was arrested for allegedly plotting to fly explosive-packed, remote controlled planes into the Pentagon and the Capitol building.

There have been number of convictions based on stings in recent years, the BBC's Adam Brookes reports from Washington.

However, Muslim groups and civil rights groups have expressed concern at the way the FBI uses stings in counter-terrorism cases.