Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A homegrown Islamic State terrorist in Britain whose plot to assassinate Prime Minister Teresa May was undone by undercover police officers was sentenced Friday to 30 years to life in prison.

Naa'imur Rahman had planned to bomb the gates of 10 Downing Street, the prime minister's official residence in London, and then "use the ensuing chaos" to get inside and kill May with either a gun or a knife, the Metropolitan Police said in a statement.

But the 21-year-old from north London made the mistake of "confiding with a network of online role-players" who were actually members of the FBI, the British MI5 secret service and the Metropolitan Police.

Naa'imur Zakariyah Rahman, 21, who planned to bomb the gates of no 10 Downing Street office, kill guards and then attack Britain's Prime Minister Theresa May. British Metropolitan Police Service / via AFP - Getty Images

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

They, in turn, steered Rahman to undercover counterterrorism police officers who arrested him in November 2017 when he arrived to collect what he thought was a homemade bomb, but what was "in fact a harmless replica."

Rahman is "an extremely dangerous and determined individual," Metropolitan Police Deputy Assistant Commissioner Dean Haydon said in a statement.

"Rahman's target was the prime minister but he had no qualms about killing innocent bystanders in the process of reaching her," Haydon said. "In fact, at one point he told a covert counterterrorism officer that even if he could not reach the prime minister he just wanted to strike fear into people."

Rahman began plotting May's murder a month before he was caught and investigators found surveillance video footage of him scoping out the area where the prime minister lives, officials said.

After making contact with what he thought was an ISIS handler, Rahman gave the officer a jacket to turn into a suicide vest and a backpack to fill with explosives.

When they rendezvoused again on Nov. 28, 2017, Rahman was handed what he thought were weapons of mass destruction.

"Now I've seen everything," he said, according to police. "It feels good."

Minutes later, Rahman was arrested, police said.

Rahman was found guilty in July of engaging in conduct in preparation of terrorist acts after a four-week trial. He also admitted helping an associate join ISIS in Libya by recording a sponsorship video for the terrorist group.

That associate, Mohammad Imran of Birmingham, 22, was also found guilty last month of collecting information useful to terrorism after investigators found a "terrorist guidance book" on his Kindle.