Naa'imur Zakariyah Rahman, who is charged with preparing acts of terrorism, was arrested on November 2 last year.
Rahman planned to detonate an explosion at the security gates of Number 10 Downing Street before stabbing the prime minister, it is alleged.
On the opening day of his trial, the jury was told how Rahman was snared in September last year, during a chat on a messaging app with an MI5 operative, who was pretending to be a man called Amir in Syria. The MI5 is UK's domestic counter-intelligence and security agency.
The trial at London's Old Bailey was also told that Rahman believed he was "just days away" from the attack before he was arrested in November last year.
Rahman is charged with preparing terrorist acts by conducting reconnaissance, recording a pledge of allegiance, and delivering a rucksack and jacket to be fitted with explosives.
He is also charged with helping a second defendant, Mohammad Aqib Imran, 22, to join ISIS in Syria by recording a sponsorship video. Rahman denies both counts, the BBC reported.
Imran, has pleaded not guilty to preparing terrorist acts and possessing a document on his Kindle entitled How To Survive In The West - A Mujahid's Guide 2015. Imran's nationality was not provided.
The court heard how Rahman told the agent that he was being investigated because of his uncle. Rahman's uncle joined the Islamic State terror group in Syria and encouraged his nephew to attack Britain before being killed in a drone strike in Syria, the prosecutors said.
Jurors were told that Rahman, when asked for more information in the Telegram chat, told the agent: "I want to do a suicide bomb on Parliament. I want to attempt to kill Theresa May."
The court heard how he also praised the Manchester Arena bomber and said he had thought about wearing "a vest" while driving past Parliament before "pushing the button" to "clear the entire block".
Rahman allegedly added: "Everyone inside, including the Prime Minister, would be dead."
Prosecutor Mark Heywood told the court: "His settled conclusion was that lethal violence here, directed at the very heart of the United Kingdom government, was the only effective way to pursue his intentions.
"Before his arrest prevented it, he was, he believed, just days away from his objective, which was no less than a suicide attack, by blade and explosion, on Downing Street and, if he could, upon the Prime Minister Theresa May herself."
Mr. Heywood claimed how both defendants - Rahman and Imran - knew each other well and shared the "warped ideology" of ISIS.
He said: "The evidence shows in detail [Rahman's] developing fervour as he first assembled his plan, carried out reconnaissance and perfected his ideas and then acquired the means to execute it."
"At the last he took back his own coat and his own rucksack both modified with improvised explosive devices, so that he could achieve his settled aim of a full-frontal assault on the gates and then the door of Number 10."
"In this he expected to die. But he also hoped for personal reward beyond death and, in doing so, to cause death and great fear in a place and to people symbolic of the country itself," Mr. Heywood said.