Advertisers are increasingly in the cross hairs of populist activists — aided by the power and reach of social media — who are demanding that brands quickly take sides on divisive social and political issues, posing a new challenge to corporations that usually prefer to stay out of the fray.

After a groundswell of online anger over reports that Bill O’Reilly, the Fox News host, had settled with at least five women who accused him of harassment, more than 50 companies pulled their ads from Mr. O’Reilly’s popular prime time program. The exodus followed similar campaigns to pressure brands with ties to President Trump, like L.L. Bean, Uber and advertisers on “The New Celebrity Apprentice.”

“Americans are now demanding that their brands articulate their values and weigh in on political issues, and I think the degree to which they are expecting that is really quite new,” said Kara Alaimo, who teaches public relations at Hofstra University and worked in communications for the United Nations, the Treasury Department in the Obama administration, and the administration of former Mayor Michael R. Bloomberg. “What social media is doing is forcing companies to make these decisions much more rapidly.”

Ad boycotts are not new: provocateurs like Don Imus and Glenn Beck lost their cable news soapboxes in part because an angry public used petitions and letter-writing campaigns to force companies to drop their sponsorship.

But the pile-on culture of social media has accelerated the process to such a degree that corporations may find themselves besieged in hours by tens of thousands of online critics.

Just this week, Pepsi was excoriated for a tone-deaf commercial that invoked the imagery of populist protest to sell soft drinks. A Twitter post from the Rev. Bernice King, the daughter of the Rev. Dr. Martin Luther King Jr., that mocked Pepsi was reposted more than 140,000 times. Within roughly 24 hours of the release of the ad, Pepsi pulled it and apologized.

The rapidity of this cycle has tested even the best-prepared marketing giants, creating a niche for public relations specialists who say they can help companies navigate these instant social media storms. One firm offers software and training sessions that simulate “a real-time online attack” on a brand — the corporate equivalent of war games.

The boycotts may give brief satisfaction to social media activists. But many of the sponsors that turned away from Mr. O’Reilly this week are still advertising on Fox News, which reaches the biggest audience on cable television. Fox says it is working with sponsors to address any concerns about “The O’Reilly Factor.” And specialists say there will be little to no financial impact on the network in the near future, though that could change over time.

Brian Wieser, a media analyst at Pivotal Research, said that for now, Fox News was essentially just shuffling inventory — “not unlike if you run a store and have got to figure out what shelf on which you put different products.” In the short term, the fallout could eat into revenue for “The O’Reilly Factor” as cheaper commercials replace big-spending brands, Mr. Wieser said, while the longer-term worry is that advertisers could reassess the annual budgets they spend on Fox News.

Even if the effect is more symbolic than financial, there is little question that social media have proved to be potent weapons.

Since November, a Twitter account called Sleeping Giants has pressured brands into removing ads that appear on Breitbart News, the conservative news and opinion website with close ties to the Trump administration. The group, which posts screenshots of advertising on Breitbart, says it has influenced hundreds of brands — citing Kellogg, Warby Parker and Allstate — to block ads from appearing on the site.

Sleeping Giants, whose proprietors have remained anonymous, extended its mission this week, urging its roughly 81,000 followers to post images on Twitter of allegations about Mr. O’Reilly to a list of advertisers. The account has then praised companies that decided to pull sponsorship.

Vulnerability to that kind of online backlash is the flip side of a new-media coin for major brands, which have spent years pursuing consumer engagement on social media. These days, big companies may try to talk like teenagers, using slang terms like “bae” and “on fleek” on their corporate accounts, or participate in viral trends like “the mannequin challenge,” an online video craze.

But social media are also handy conduits for people to register their anger with brands — directly and en masse.

“The intensity of this is a lot greater,” said Matthew Hiltzik, a former Democratic consultant who draws on his experience in rapid-fire political campaigns to advise corporate clients. “Companies need to invest time and resources in developing proactive strategies that advance and protect the brand, so that they are best prepared to deal with the unexpected.”

Weber Shandwick, the public relations firm, created a simulation software and training tool called “Firebell” in 2010 to prepare clients for social media maelstroms. Its website describes a new strain of crisis “made up of a string of critical nano-moments,” which can “gain momentum and mass at inferno-speed.” Firebell, introduced as one facet of responding to a crisis, is now central to the firm’s crisis management training, a spokesman said.

Brands are particularly concerned that they can be unaware of where their messages are showing up until angry consumers come calling. In recent months, news outlets and activists have discovered prominent companies inadvertently financing a wide range of objectionable material online through automated ad placement, including sites that traffic in fake news and racist and terrorism-related videos on YouTube.

The pressure represents some whiplash for an industry that had broadly moved away from relying on content as a rough proxy for groups of people, focusing instead on targeting online ads, and to a lesser extent, television ads, by audience size, browsing habits and other user characteristics.

Orkin, a pest-control company that removed its ads from “The O’Reilly Factor,” does not buy ads on specific shows but instead purchases “broad day parts on networks that reach our target audience,” Martha Craft, a spokeswoman, said. The company added Mr. O’Reilly’s show to a “Do Not Buy” list after learning of the allegations against him, she said.

This year, consumers pushed brands to distance themselves from “The New Celebrity Apprentice” because Mr. Trump remained an executive producer of the show. That effort stemmed from #GrabYourWallet, a grass-roots social media campaign that urges boycotts of companies selling Trump-related products.

“We haven’t seen brands almost treated as individuals in this way before, and expected to espouse political beliefs and uphold them consistently across platforms in everything they do,” Ms. Alaimo said.

Many companies are still figuring out how to cope with these situations, she said, adding that it was crucial to respond during “the golden hour of crisis.” The term refers to the “golden hour” in emergency medicine — the window after a traumatic injury in which treatment is most likely to stave off death or permanent damage.

Marc S. Pritchard, the chief brand officer at Procter & Gamble, the world’s biggest advertiser, has overseen global marketing for the company since 2008. He said that when he started in the role, one of the first items on his agenda was working with the media team to “renew our standards” for television and radio ads.

“There were some issues where some of the content was becoming objectionable to a large portion of our consumers, whether it was too much graphic violence, too much either sex or sexual innuendo,” Mr. Pritchard said in an interview at an industry conference this week.

He said that while the media landscape has radically shifted since then, his company maintains the same standards for where its ads should appear.

“I was once told, very early back in my marketing career, your brands are judged by the company they keep,” he said.