LONDON (Reuters) - A British man was sentenced to life in prison on Friday over a plot to kill Prime Minister Theresa May by first detonating an explosive device to get into her Downing Street office and then using a knife or a gun to attack her.

Britain's Prime Minister Theresa May addresses a joint news conference with Kenya's President Uhuru Kenyatta at the State House in Nairobi, Kenya August 30, 2018. REUTERS/Baz Ratner

Naa’imur Rahman, 21, of north London, planned to detonate an improvised explosive device at the heavily guarded gates of Downing Street and gain access to May’s office in the ensuing chaos and assassinate her, according to police.

He was convicted last month of preparing to commit acts of terrorism and at London’s Old Bailey court on Friday was given a life prison and will serve 30 years behind bars.

“Rahman’s target was the prime minister but he had no qualms about killing innocent bystanders in the process of reaching her,” said Dean Haydon, the UK’s Senior National Coordinator for Counter Terrorism.

“At one point he told a covert counter terrorism officer that even if he could not reach the Prime Minister, he just wanted to strike fear into people.”

As he put the plot together, Rahman believed he was corresponding online with members of the Islamic State (IS) militant group. However, he was actually talking to undercover officers from the U.S. Federal Bureau of Investigation (FBI) and Britain’s MI5 domestic spy agency.

He was arrested last November shortly after unwittingly meeting an undercover police officer and collecting what he believed was a homemade bomb but was in fact a harmless replica.

After his conviction in July, police said Rahman had been in contact with an uncle who had traveled to Syria and joined IS and who had encouraged his nephew to carry out attacks in Britain.

Rahman had been planning to carry out the attack for two years but his resolve was hardened when he heard that his uncle had been killed in a drone attack.

Britain is on its second highest threat level with an attack considered highly likely. Last year, there were four deadly attacks and the head of MI5 said in May that a further 12 Islamist plots had been foiled since the first of these in March 2017.

Earlier this month, a man was charged with attempted murder after a car careered into people and a barrier at London’s parliament, with police saying the incident was being treated as an act of terrorism.