Supporters of presidential candidate Donald Trump who were roughed up by protesters at a June 2016 campaign rally in San Jose can sue the city and its police for allegedly putting them in danger and then failing to protect them, a federal appeals court ruled Friday.

If the allegations are true, “the officers acted with deliberate indifference to a known and obvious danger” and violated the Trump supporters’ constitutional rights,” said the Ninth U.S. Circuit Court of Appeals in San Francisco.

After the rally at the McEnery Convention Center, police directed those in attendance to leave from a single exit. There, according to the lawsuit, they were ordered to head out onto a street where hundreds of anti-Trump protesters were waiting, even though a safer route and other exits were available.

Twenty plaintiffs in the suit said they were beaten or struck by objects thrown by the protesters, and one plaintiff said an officer told her that police had been instructed not to intervene. The plaintiffs said police arrested three people for allegedly assaulting officers, but no one for attacking Trump supporters.

San Jose Police Chief Eddie Garcia praised the officers after the rally “for both their effectiveness and their restraint” and said “additional force can incite more violence in the crowd.”

Lawyers for the city said police did not create the danger and should not be second-guessed for legitimate law enforcement decisions, like the one to use a single exit. But the court said the officers, according to the allegations in the lawsuit, had known of violence at past pro-Trump rallies and were reporting assaults outside the convention center in the hours before the San Jose rally.

“The attendees allege the officers shepherded them into a violent crowd of protesters and actively prevented them from reaching safety,” Judge Dorothy Nelson said in the 3-0 ruling that upheld a federal judge’s refusal to dismiss the suit. “The officers continued to implement this plan even while witnessing the violence firsthand” and even though they knew about the earlier attacks outside the convention center, she said.

If the plaintiffs can prove their allegations, Nelson said, they would show that police increased the danger to the rally-goers and knowingly exposed them to a risk of injury.

Harmeet Dhillon, a Republican national committeewoman who is the lawyer for the Trump supporters, said she was pleased the court “agreed with us that, where police put citizens into harm’s way, they can be held liable for the consequences.” The lawsuit, she said, “seeks to vindicate important civil rights of all Americans.”

San Jose City Attorney Richard Doyle said the city disagrees with the court’s view of the law on police liability, and with “the plaintiffs’ view of the facts.” He said his office would consult with the City Council on a possible appeal.

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko