The Supreme Court has been accused of using “stereotypes” to justify the “targeting of young black men” after five judges gave their strong backing to the police’s random stop and search powers.

A legal challenge brought by a black mother from north London who was searched under the powers was dismissed by five judges today. They argued that stop-and-search saved black lives by curbing gun and knife crime.

But campaign group StopWatch called the court’s decision “shocking” and “disappointing” and warned it risked eroding trust in the police.

“It is particularly shocking that the Supreme Court justifies the targeting of young black men by associating them with gang violence,” said Natasha Dhumma, the group’s senior engagement officer.

“The young black and minority ethnic people we work with tell us they are sick of such baseless assumptions being used to rationalise their harassment by police through suspicionless stop and search.”

She added: “This judgment speaks to stereotypes, not to the realities faced by many young people across the country.”

In the first case of its kind, judges in the highest court in the land, unanimously ruled that section 60 of the 1994 Criminal Justice and Public Order Act, which allows random searches, is “in accordance with the law” and compatible with the European Convention on Human Rights.

Deputy president Lady Hale, sitting with Lord Clarke, Lord Reed, Lord Toulson and Lord Hodge, ruled there were adequate safeguards in place and “great benefits to the public in such a power”, particularly to black people. She said: “Put bluntly, it is mostly young black lives that will be saved if there is less gang violence in London and other cities.”

Ann Juliette Roberts, brought the case after she was searched for failing to pay a bus fare and “behaving suspiciously” on a route police say is used by local gangs. Mrs Roberts argued that stop-and-search powers are used disproportionately against black people, breaching their human rights, but her case was rejected by the High Court and Court of Appeal before she took it to the Supreme Court.

Dismissing the latest appeal, Lady Hale and Lord Reed observed that the purpose of the searches was to “reduce the risk of serious violence where knives and other offensive weapons are used”.

The judges added: “It must be borne in mind that many of these gangs are largely composed of young people from black and minority ethnic groups. While there is concern that members of these groups should not be disproportionately targeted, it is members of these groups who will benefit most from the reduction in violence, serious injury and death that might result from such powers.”

The controversial powers have been subject to an ongoing review ordered by Home Secretary Theresa May to ensure they are applied fairly.