A terror plot to bomb the London Underground or Westfield shopping centre was foiled shortly before the 10th anniversary of the July 7 attacks, a court heard.

Counter-terrorism officers were alerted to the plan after Mohammed Rehman, under the name Silent Bomber, asked Twitter followers for advice on which of the two targets to choose, jurors were told.

Meanwhile, he allegedly bought ingredients for explosives on eBay with the help of his secret wife Sana Ahmed Khan, and even filmed himself testing a bomb in his back garden.

When the would-be suicide bomber was arrested on May 28, he boasted of having a "surprise" for police, the court heard Rehman said he had rigged up a bomb which could be triggered at the touch of a button at his bedside, saying: "Nobody gets in the way of my Jihad."

What officers actually found were a Jihadi John-style hunting knife and chemicals for a massive bomb that could have caused "multiple fatalities" and was just days away from being completed, jurors were told.

Rehman, 25, and Khan, 24, are on trial at the Old Bailey charged with preparing terrorist acts on or before May 28 this year. Rehman is also charged with possessing an article for terrorist purposes.

Opening the trial, prosecutor Tony Badenoch QC said the pair had a "common interest" in violent and extreme Islamic ideology and had repeatedly researched 7/7 bombers.

They also had a keen interest in Islamic State, and Rehman's online research showed he approved of their atrocities and "wished to play his own part", jurors were told.

On May 12, he allegedly posted a public tweet using the handle Silent Bomber with a profile picture of Jihadi John, saying: "Westfield shopping centre or London underground? Any advice would be appreciated greatly."

The post was accompanied by a link to the al Qaida uncensored media release about the 7/7 bombings.

The prosecutor said: "The evidence suggests that the London Underground may well have been on his mind as a potential target as he was particularly fixated with the events of 7/7 and he referred to Shehzad Tanweer, one of the 7/7 suicide bombers, as his 'beloved predecessor'."

The same day, Rehman repeatedly trawled YouTube for material about the London bombings and Tanweer, the court heard.

He also told a Twitter user: "Why don't you head to the London Underground on the 7th July if you got the balls."

On July 7 2005, 52 people lost their lives and more than 770 were injured in the "worst terrorist atrocity in this country since Lockerbie in 1988 and this country's first ever suicide bomber attack", the prosecutor said.

Counter-terrorism spotted Rehman's Tweets of May 12 and swooped 16 days later - just over a month before the 10th anniversary of the 7/7 atrocity.

The prosecutor said the couple had no "idle fantastical interest" in terrorism and were committed to "researching, purchasing, testing and manufacturing a substantial amount of bomb-making wherewithal".

On May 28, officers seized more than 10kg of urea nitrate - a highly explosive chemical - which if detonated "would have caused multiple fatalities in a public place".

Rehman was "intent on martyrdom" and was unequivocal when he tweeted: "I have other plans if Insha Allah goes to plan and I'm preparing for an Istishaadi (martyrdom) operation".

He also allegedly tweeted: "Now I just make explosives in preparation for kuffar lol and when I've made the required amount I'll be wearing them on my chest."

The chemicals seized from his home showed these were no "attention-seeking boasts" as they were capable of being turned into lethal bombs "ready to go", Mr Badenoch said.

He added: "Given his prior knowledge, experience and the ready availability of the chemicals, the manufacture of a detonator would have taken no more than a couple of days and could have been done by him much quicker if he chose to."

Rehman allegedly tested explosives in his back garden at least twice and on one occasion he videoed the blast and sent the film to his wife, the court heard.

On the day of his arrest, Rehman fled his home but was arrested outside a Co-Op after his efforts to escape by kicking and punching were thwarted by firearms officers, the court heard.

He told police there was nothing dangerous in his home when he was given a safety interview, despite tweeting that he had "a surprise waiting for them".

Police found a hunting knife in the house which was similar to those used in extremist imagery, in particular by Jihadi John, as well as the extremely dangerous chemicals.

He also allegedly said: "I've rigged my house to blow at the touch of a button by my bedside if the popo try to raid man. Nobody gets in the way of my Jihad." In fact he had not got this far, the court heard.

Mr Badenoch told jurors: "It is difficult to conceive of a clearer threat to counter-terrorism officers than those articulated by him in those two messages; a 'surprise' whether his hunting knife or chemicals, and a bomb to be triggered to the touch of a button by his bedside, waiting for law enforcement seeking to counter extremist Islamic terrorism."

Almost simultaneously, Khan was arrested at her family home and when asked if there were any hazardous materials that could injure or kill, she said: "I don't know, I don't go to his house."

Khan, who studied to degree level at the University of Greenwich in south-east London, had known Rehman for 10 years.

She kept their Islamic marriage a secret from her family who did not approve of the drug-taking Rehman, and they stayed living separately with their parents and siblings, the court heard.

Mr Badenoch told jurors that Rehman frequently had violent arguments with his family, causing his fearful father to spend time away and even sleep rough to avoid him.

Rehman, of Radstock Road, Reading, and Khan, of Hutton Close, Reading, deny wrongdoing and the trial continues.