BERKELEY, Calif. -- An anti-hate rally was disrupted when scores of anarchists wearing black clothing and masks stormed the demonstration in Berkeley and attacked several supporters of President Trump. But police were able to head off any wider violence.

Thousands gathered Sunday in response to a planned anti-Marxism protest that was canceled amid concerns demonstrators might be attacked. The counter-demonstration was largely peaceful for several hours until the antifa, or anti-fascists, overran police barricades around the protest area. The violence was swift but brief, and among those targeted was Joey Gibson, leader of the right-wing organization Patriot Prayer that had called off a demonstration a day earlier in San Francisco.

Berkeley Police Chief Andrew Greenwood said officers were told not to actively confront the anarchists. He applauded officers' restraint, saying it forestalled greater violence. Six people suffered injuries, including two who were hospitalized, and one officer was injured while making an arrest and several others were hit with paint.

Get Breaking News Delivered to Your Inbox

There were 13 arrests on various charges including, assault with a deadly weapon.

"The potential use of force became very problematic" given the thousands of peaceful protesters in the park, Greenwood said. Once anarchists arrived, it was clear there would not be dueling protests between left and right so he ordered his officers out of the park and allowed the anarchists to march in.

There was "no need for a confrontation over a grass patch," Greenwood said.

Several hours later, the demonstration broke up without any further incidents.

Officials in Berkeley and San Francisco had been girding for the possibility of violent clashes at right-wing demonstrations. But Saturday's in San Francisco by Patriot Prayer was called off, and police blocked access to a public square where Gibson had planned to hold a news conference. He instead held it outside the city and criticized police for not doing enough to ensure supporters' safety at the originally scheduled location of Crissy Field.

Still, hundreds of counter-protesters marched through the city. San Francisco Police Chief Bill Scott said Saturday that police made a single arrest, for public intoxication, during demonstrations organized by left-wing groups.

The anti-Marxist rally in Berkeley was organized by Amber Cummings, a transsexual Trump supporter. Citing the potential for violence, she canceled the event but said she would show up on her own. She was not seen there, though Gibson vowed to come and when he did, anarchists set upon him.

They pepper-sprayed him and chased him as he backed away with his hands held in the air. Gibson rushed behind a line of police wearing riot gear, who set off a smoke bomb to drive away the attackers.

Separately, groups of hooded, black-clad protesters attacked at least four other men in or near the park, kicking and punching them until the assaults were stopped by police. The assaults were witnessed by an Associated Press reporter.

At one point, an anti-rally protester denounced a Latino man holding a "God Bless Donald Trump" sign.

"You are an immigrant," Karla Fonseca said. "You should be ashamed of yourself."

Several other people also yelled at the man, who said he was born in Mexico but supports Trump's proposal to build a wall along the border.

Groups that planned the counter-demonstrations were concerned that white nationalists might show up and there would violence like the kind two weeks ago in Charlottesville, Virginia, where a woman was killed. No white nationalists showed up, and only a handful of pro-Trump demonstrators were visible in the crowd.

Police pulled one Trump backer out of the park over a wall by his shirt as a crowd of about two dozen counter-demonstrators surrounded him and chanted "Nazi go home!" and pushed him toward the edge of the park. At least two people were detained by officers for wearing bandannas covering their faces.

Anti-rally protesters chanted slogans "No Trump. No KKK. No fascist USA" and carried signs that said: "Berkeley Stands United Against Hate."

Berkeley Mayor Jesse Arreguin issued a statement early Sunday evening praising the majority of protesters who remained peaceful during Sunday's events, reports CBS San Francisco.

"I applaud the more than 7,000 people who came out today to peacefully oppose bigotry, hatred and racism that we saw on display in Charlottesville. They gave impassioned speeches, they played music and they showed that Berkeley and the Bay Area will always stand for tolerance, diversity and justice," the statement read.

"Faced by extremists who were intent to fight, the Berkeley Police Department made the right call to deescalate the situation," the statement continued. "In the end, 13 people were arrested and two taken to the hospital. I regret that people were injured, but am glad that serious violence was averted."

In the days leading up to the planned events, Cummings and Gibson, who is Japanese-American, consistently denounced racism. In a video he posted on Patriot Prayer's Facebook page, Gibson said he is a person of color and so if he were in favor of white nationalism "I'd have to punch myself in the face."

Gibson said Saturday he was planning to organize a rally Sept. 10 in Portland, Oregon.

Meantime, newly appointed University of California, Berkeley Chancellor Carol Christ said the campus was "working very hard on the security arrangements" for the Sept. 14 appearance of conservative commentator Ben Shapiro.

Campus officials will add more police to the event than were present for the scheduled appearance of another conservative, Milo Yiannopoulos, Christ said. That planned talk was canceled when demonstrations turned violent in February.

Student activism was born during the 1960s free-speech movement at Berkeley, when thousands of students at the university mobilized to demand that the school drop its ban on political activism.