Authorities in San Francisco and Berkeley are planning a large show of force this weekend at two right-wing rallies, enlisting hundreds of officers each day in a bid to prevent violence from erupting in the wake of the killing of an antiracism protester in Charlottesville, Va.

While urging people to stay home, officials on both sides of the bay said Tuesday that they were boosting staffing and bringing in outside help to ensure order among what could be dueling crowds at Saturday’s Patriot Prayer rally at Crissy Field and Sunday’s No Marxism in America event at Berkeley’s Civic Center Park.

The San Francisco Police Department said all available officers would be on the job, with overtime shifts required.

The rallies, together billed as Liberty Weekend in the Bay Area, are expected to be magnets for far-right extremists, and authorities have expressed fear that confrontations between them and counterprotesters could escalate into the sort of bloody, video-recorded skirmishes seen in Charlottesville on Aug. 12, in Berkeley earlier this year and in Sacramento last summer.

Police in Berkeley and beyond have been criticized at times for not doing enough to head off the violence, and have worked to improve their strategies. The idea behind using hundreds of officers, said Bay Area officials and law enforcement experts, is to maintain the ability to separate people who may clash, while not having to resort to heavy use of force.

“There obviously needs to be a strong police presence,” said Robert Weisberg, a Stanford criminal justice professor and a co-director of the university’s Criminal Justice Center. “With good motives or bad, a member of one group can mix in with the other and cause trouble. You can’t stop that. That means police have to be right there on the spot to detect that and neutralize it.”

Extreme groups on the right have increasingly mobilized since President Trump took office, most recently in Boston on Saturday, where a small group of demonstrators was drowned out by tens of thousands of counterprotesters. Some public officials wish community members would ignore the rallies, which are designed to be provocative, but many activists believe the views must be confronted.

In San Francisco, a fringe group called Patriot Prayer has received tentative approval from the Golden Gate National Recreation Area to hold a “free speech” rally for 300 people at 2 p.m. Saturday at the park-run Crissy Field. The group insists it’s not tolerant of bigotry, but its prior events have sought to stir unfounded fear of Muslim Americans, and have drawn people espousing hateful ideology.

While federal park officials say they’re re-evaluating whether to proceed with the event due to widespread concerns about violence, they also say they are inclined to honor the group’s First Amendment rights. A final decision on the matter is pending.

San Francisco Mayor Ed Lee, along with House Minority Leader Nancy Pelosi and Sen. Dianne Feinstein, have publicly called for the Park Service to rescind the group’s approval. Behind the scenes, the mayor and others have been pushing park officials to put restrictions on demonstrators, should the rally go forward, such as banning items that can be used as weapons.

Officials at Golden Gate National Recreation Area, who have declined several interview requests, said in a public statement last week that they were working on a safety plan, and had been in talks with the city.

However, Pelosi, speaking Tuesday to reporters after a Women’s Equality Day event on the Embarcadero, questioned the ability of the Park Service to keep the peace at such a large event, which could put families, tourists and other visitors at risk.

While turnout remains uncertain, a handful of counterprotests have been planned for Saturday, including an anti-white nationalist rally at San Francisco’s Civic Center Plaza and an antiracist march at Crissy Field.

San Francisco police officials said they were still waiting to learn the conditions under which the Patriot Prayer protest will proceed, but would plan for whatever activities are sanctioned. The officials, similar to their counterparts in Berkeley, declined to go into detail about their expected tactics to preserve the element of surprise.

“We’re working closely with park police to facilitate First Amendment rights and ensure that people who are coming as participants or to protest will be safe,” said Officer Giselle Linnane, a San Francisco police spokeswoman.

The situation is similar in Berkeley, where counterprotests are planned alongside Sunday’s rally at 1 p.m. at Martin Luther King Jr. Civic Center Park.

While the unpermitted rally has been advertised online as an anti-Marxist demonstration, Berkeley Mayor Jesse Arreguin said Tuesday he expected white nationalists to use it as a platform to spread their views and possibly incite violence. He said he expected thousands to show up and discouraged the public from going anywhere near the park.

“They have called it the Battle for Berkeley 3,” Arreguin said, referring to clashes between right-wing groups and black-masked counterprotesters in March and April that yielded injuries and arrests. “When you come dressed like a soldier, you’re not interested in freedom of speech. You’re interested in violent provocation. We want to be sure we prevent violence. We welcome peaceful assembly and debate.”

Berkeley passed a measure Friday that allows the city manager to create and enforce temporary rules around Civic Center Park. That means police could confiscate weapons and set up fences on public sidewalks for crowd control. A batch of such rules is expected Sunday morning.

Former San Francisco Police Chief Tony Ribera said bringing in large numbers of officers for an event allows police to handle unforeseen events. Even if 80 or 90 percent of people attending a demonstration are peaceful, he said, it only takes 10 percent to push things out of hand.

He noted that the unexpected turn in Charlottesville, as well as last week’s deadly terror attack in Barcelona, was the use of a car as a weapon. “Part of crowd control now,” he said, “is also vehicle control.”

The challenge for law enforcement, said Berkeley civil rights attorney Jim Chanin, who has sued police in Berkeley and other cities for alleged abuses during protests, is finding the balance between protecting and provoking a crowd.

“An in-your-face presence by the police can antagonize a crowd,” Chanin said. “However, that doesn’t mean there shouldn’t be large numbers available and nearby. That is the trick, to have large numbers that can move in without making those large numbers a provocation themselves.”

Boston authorities found the right balance, and there was little violence, he said.

“Hopefully,” Chanin said, “the police will learn something from that.”

Lizzie Johnson and Kurtis Alexander are San Francisco Chronicle staff writers. Email: ljohnson@sfchronicle.com, kalexander@sfchronicle.com Twitter: @lizziejohnsonnn @kurtisalexander