A Muslim convert on trial for plotting to kill a soldier told police he also wanted to attack Prime Minister David Cameron, a terror trial was told.

Brusthom Ziamani, 19, allegedly made the threat during an interview with officers, after he was caught en-route to a military base armed with a hammer and a knife, wrapped up in an Islamic flag.

Under questioning by police, Ziamani confirmed his wish to attack the prime minister, the jury at the Old Bailey was told.

A section of the exchange was read out in which the suspected Muslim extremist confirmed he said the threat while a recorder was not working.

"What would you do if you saw David Cameron and had an opportunity? asked a police officer. "You said you would do him harm if he had no security around?" Ziamani replied: "Yes."

The alleged threat is the latest to be made against the heart of power in Britain, after a Muslim fanatic spoke of his wish for the black flag of terror group Islamic State to fly over Downing Street. Earlier in February, 20-year-old David Souaan was jailed for preparing acts of terrorism in war-torn Syria.

Arrested in 2014, Ziamani is accused of preparing an act of terrorism, which he denies.

Prosecutors allege he searched online for army bases near to his home in Camberwell, south London, and hero-worshipped the killer of soldier Lee Rigby, the radical Muslim Michael Adebolajo.

The trial continues.