An undercover police officer was a “criminal operative” who planted evidence including an apparent pipe bomb and handgun in the car of a terrorism suspect, a jury has heard.

The claim was made during the officer’s cross-examination at the trial of a group of men from the Midlands who are accused of preparing terrorist acts between May and July 2016.

Naweed Ali, 29, and Khobaib Hussain, 25, neighbours from Sparkhill in Birmingham, are on trial at the Old Bailey alongside Mohibur Rahman, 32 – they described themselves on the messaging app Telegram as the ‘three musketeers’ – and Tahir Aziz, 38. They deny the charges.

The officer, who gave his name as Vincent, posed as the boss of a fake courier firm, Hero Couriers, that was set up by MI5 and West Midlands police as part of an elaborate joint counter-terrorism operation.

He hired Ali and Hussain as delivery drivers in July and August. On 26 August, Ali’s first day in the job, MI5 officers searched his car at the Hero Couriers depot and carried out a “technical operation” while he was making a delivery.

They found a bag containing what was believed to be a handgun, a pipe bomb, shotgun shells, a cleaver and other items, and the defendants were arrested that day.

When they discovered the items, everyone was ordered to leave the depot. But Vincent remained in the building and with the help of another undercover officer, “Andy”, moved a mat on which the items had been spread into a separate room. Andy then left with the MI5 officers.

“Nobody in their right mind who actually believed this was a real bomb would have moved it … the only reason you did it was because you knew this was not a real bomb,” Ali’s defence barrister Stephen Kamlish QC told the officer.

“And how would I know that?” Vincent asked.

“Because you put it there,” Kamlish replied.

“I would like to know on what basis the counsel can accuse me of planting that bomb in the car … I would never be involved in anything like that, I have never and will never,” Vincent told the court. The decision to move the bomb was a “calculated risk” and the device had already been moved when it was taken out of the car, he said.

Kamlish said Vincent also knew the apparent handgun was actually an air pistol, even though in a recording he made of himself examining the contents of the bag he said it was possibly real. Notes made by his superior officer suggested they had discussed the possibility it was an air pistol, Kamlish said.

Vincent had “faked up a find” in the recording, Kamlish said, adding: “If you told your boss over the phone at least once probably twice … that you thought it might be or was an air pistol then you must have planted it.”

“I didn’t say that,” Vincent replied. “We had conversations about my opinion of what it actually was. And we both knew that with no thorough examination there was no way of telling exactly what it was … I’ve already explained to this court that the notion I planted anything in that bag is ridiculous.”

Vincent, who gave evidence from behind a curtain shielding him from the public and defendants, described himself as a “law enforcement officer” refused to confirm this meant he was a police officer or who his employer was, saying this had “no bearing whatsoever on my answers”.

Kamlish replied: “We are accusing him of being an underhand criminal operative in order to secure convictions … He’s been put into this position in order to bring a corrupt case against my client.”

He added: “His failure to answer these questions is in our submission relevant … I’ve never come across a position where if you ask someone if they are a police officer, and they are, they don’t say yes.”

At the heart of the case is the distinctive yellow, blue and green JD Sports bag that the gun, apparent bomb and other items were found in. MI5 discovered it under the driver’s seat of Ali’s car, a black Seat Leon. Vincent described seeing Hussain carrying the bag several times.

Ali’s lawyers say Vincent planted it in Ali’s car because Hussain’s car had already been bugged, so any attempt to plant it in there would be picked up by surveillance.

Vincent repeatedly refused to answer whether a search and technical operation had been carried out on Hussain’s car when he started work at Hero Couriers in July 2016, saying he could not disclose this on national security grounds.

Kamlish told the court a fibreoptic camera, a listening device and a GPS tracker had been installed in Ali’s car by MI5.

“There must have been a similar operation on Khobaib Hussain’s [car],” Kamlish said.

“My lord, I’m afraid I cannot answer that question on grounds of national security,” Vincent replied.

From Hussain’s first day in the job, Kamlish said, “there was a bug at least and probably a camera as well in his car, which meant that you could not enter it to either search it or plant anything in it for the whole of July and the whole of August.”

“I’m afraid I can’t answer the first part of that question, but the second part, when you use the word plant, I would like to know on what basis I’m accused of planting evidence,” Vincent replied.

Kamlish said this would become clear during the rest of the cross-examination, adding: “The reason the bag was finally found allegedly on 26 August in somebody else’s car was because … you had a window of about an hour and a half to do whatever you were going to do before the bug was put in,” referring to the gap between when Ali left on the delivery job and when MI5 agents arrived at the fake company’s depot. “That was your only opportunity to incriminate these people after Hussain’s first visit,” he said.

“That’s an interesting work of fiction, I’m afraid,” Vincent replied. “Nothing you’ve just said to me makes any sense whatsoever, so no.”

The case continues.