British prosecutors told a court in Westminster that a man charged with the killing of a member of Parliament had been planning similar attacks for years and that he had considered himself affiliated with the Islamic State.

Ali Harbi Ali, a 25-year-old from London, has been charged with murder and preparing acts of terrorism, the Crown Prosecution Service announced before his court appearance Thursday.

David Amess, a long-serving British lawmaker, was fatally stabbed Friday while meeting with constituents in a church annex in Southend, Essex. Authorities arrested Ali shortly afterward and held him for questioning in London under Britain’s Terrorism Act.

The death of Amess, 69, a member of Prime Minister Boris Johnson’s Conservative Party, shook Britain, where members of Parliament often meet with the public without security. It was the second killing in recent years of a British lawmaker attending a public event: Jo Cox, a member of Parliament from the Labour Party, was fatally shot and stabbed in 2016 while on her way to meet with constituents.

Appearing in Westminster Magistrates’ Court on Thursday afternoon, Ali wore a gray prison-issue tracksuit and spoke only to confirm his name, age and address. He did not enter a plea.

“Ali considered himself affiliated to [the] Islamic State,” prosecutor James Cable told the court, the Reuters news agency reported. Earlier in the day, the Crown Prosecution Service told reporters that the crime “has a terrorist connection, namely that it had both religious and ideological motivations.”

The details of Ali’s alleged affiliation with the Islamic State were not revealed in court Thursday. The son of a media adviser to a former prime minister of Somalia had grown up in Croydon, south London.

The Telegraph reported Thursday that Ali had worked at King’s College Hospital in London and underwent training in the radiography department, but that he had not worked for the hospital or Britain’s National Health Service since at least 2019.

The paper had previously reported that in 2014, while still in school, Ali had been referred to Prevent, a counterterrorism program run by the British government. He was later declared not to be a risk and wasn’t flagged to intelligence agencies, the Telegraph reported.

British police have said they are not looking for anyone else in connection with Amess’s death. Ali was ordered Thursday to remain in custody and will appear at the Old Bailey criminal court on Friday.

On Wednesday, British Home Secretary Priti Patel told Parliament that the threat level for an attack on members of Parliament was being raised to “substantial,” which means an attack is considered likely.

Read more: