The horrific terrorist attack at London Bridge on Friday afternoon demonstrated both the very best of humanity, and the very worst. On the one hand, we saw ordinary Londoners going about their daily lives, and the brave men and women of our emergency services rushing headlong into danger with barely a thought for their own safety to protect the lives of others.

I will never forget the clips of three people (one a foreign EU citizen) taking on an armed and homicidal attacker with a whale tusk, a fire extinguisher and their bare hands. They and the police who joined them are truly the best of us.

On the other hand, we saw a man, previously convicted of terror offences and sickeningly unrepentant, intent on attacking innocent people and, by doing so, assailing our values, threatening our way of life and dividing our communities. Two people died and three others were taken to hospital as a result of this cowardly attack. My heart goes out to them, their families and loved ones, and everyone who was caught up in, and affected by, Friday’s attack.

I’d like to pay a special tribute to London’s incredible emergency services for their swift, professional response. I had the honour of spending time with them on Friday and Saturday and thanking them, on behalf of all Londoners. The best part of my job is getting to know these courageous people, who sacrifice so much – mostly unseen – to keep the rest of us safe. There will be more armed and unarmed officers on London’s streets in the days ahead to reassure everybody as they go about their normal business, as I urge them to do. We owe our police and security services a huge debt of gratitude.

We simply must act to strengthen our communities and insulate ourselves against this perverse ideology

Terrorists have tried to sow fear, hatred and division in our city before. They have never succeeded, and will not succeed now. London will not be intimidated or cowed by terrorism. Rather, we will redouble our efforts to stand resolute, defiant and united in the face of such evil. Terrorism is an act of complete cowardice and we will pursue and bring to justice anyone who might have offered support to this pathetic individual.

This incident is yet another warning that we must do far more to root out the poison of extremism. We simply must act to strengthen our communities and insulate ourselves against this perverse ideology, and take the fight to those disgusting individuals who seek to recruit and radicalise vulnerable people for terrorist causes.

There will be serious questions for the government to answer in the weeks ahead about how this attack could have happened and whether it could have been prevented. It has brutally exposed the impact on our justice system of a decade of austerity. Since becoming mayor, I have repeatedly warned of the impact of police cuts on public safety – and it is devastating to have to repeat these warnings in the aftermath of another terrorist attack. However, the government must also urgently review the impact of nearly 10 years of funding reductions and ill-advised reforms to sentencing, prisons and the probation service – all of which are at breaking point as a result of budget cuts and botched attempts at privatisation.

Questions must be asked too about the government’s decision in 2012 to end judges’ ability to hand down “indeterminate sentences” that helped protect the public from violent and serious offenders. I voted against that government move at the time and I still oppose it today. The public, whom we are elected to serve, find it shocking that somebody who was released on licence from custody after serving half their sentence for committing a serious terrorist offence should be able to commit such a heinous attack.

Judges need to have the right tools to play their part in keeping us safe; prison and probation services need to be properly resourced to rehabilitate offenders; the Ministry of Justice needs to be able properly to supervise potentially dangerous people after their release. These issues all need addressing urgently.

I ask all Londoners to remain vigilant and to report anything suspicious to the police. I will continue working closely with the police, authorities and government to reassure our communities and ensure that all possible measures are put in place to protect Londoners. I have no doubt that in the coming days Londoners will once again show the world exactly why our capital is the greatest city in the world. We will not let anyone divide us or disrupt our way of life. We will defend our values – and we will never let the terrorists win.

•Sadiq Khan is mayor of London