A former soldier accused of spying for Iran launched a "hare-brained" scheme to become a double agent but "without betraying or hurting anyone", according to his defence.
Daniel Khalife was "naive" and at times "stupid", Gul Nawaz Hussain KC told the jury at Woolwich Crown Court, but he insisted the defendant was innocent.
He added that if Khalife "had not contacted MI5 or MI6 no one would ever know what he was doing. Why would he report himself if he was a real spy?"
Khalife, 23, from Kingston, southwest London, is on trial accused of spending more than two years passing secrets to the Iranians while serving with the Royal Corps of Signals.
He denies the charges and claims he handed over fabricated documents in an attempt to become a double agent.
He was only caught after twice contacting MI5 and later escaped from prison under a food catering van, causing a nationwide manhunt.
Khalife previously told the court he had decided to launch his own "operation" after being told he was unlikely to get vetted for a role with the special forces because his mother is Iranian.
Referring to the "operation", Mr Hussain said it was "crazy perhaps, hare-brained in some respects perhaps, but one he was able to carry out without betraying or hurting anyone, other than himself".
Earlier, Mark Heywood KC, prosecuting, said in his closing statement that Khalife "drove a coach and horses through the rules and he did so knowingly and for an entirely selfish purpose".
"It is not serving the interests of this country one little bit. It is serving the interests of one man - Daniel Khalife," Mr Heywood said.
He added that Khalife "appeared to have a high opinion of his own ability despite his age and complete ignorance of this type of activity but his experience was zero and he had no authorisation".
"If you cross the line and start messing with a foreign intelligence service, your purposes are quite clearly prejudicial to the interests and security of the state," Mr Heywood told the court.
Read more from Sky News:
Jeremy Clarkson demands tax U-turn
Google's AI chatbot tells user 'please die'
Why is there talk of World War Three?
Mr Heywood added that none of the fake documents Khalife prepared were without problems, each involving "a degree of risk" to the procedure, operations, national security or the country's relationship with its allies anywhere in the world.
They included one that said the Foreign Office would refuse to negotiate for the freedom of Nazanin Zaghari-Ratcliffe who was then in jail in Iran.
"It appears that thought was either missing from Khalife's computations or, if it wasn't, it was not of his concern," Mr Heywood said.
Khalife had also compiled a list of special forces non-commissioned officers which Mr Heywood claimed Khalife intended to pass to the Iranians.
Khalife denies committing an act prejudicial to the safety or interests of the state, eliciting information about members of the armed forces and perpetrating a bomb hoax.
The trial continues.
(c) Sky News 2024: Daniel Khalife trial: Ex-soldier accused of spying for Iran was 'hare-brained