Last fall, former Bill Clinton aide Chris ­Lehane huddled with top Airbnb executives in conference rooms that were replicas of Airbnb listings across the world. A year into the job as the home-sharing company’s head of policy, he faced one of his biggest crises yet: allegations that racism flourished on Airbnb’s platform.

A Harvard University study had found guests with African American names were more likely to be rejected by Airbnb hosts than those with distinctively white-sounding names, a finding that led to a class-action lawsuit and a hashtag, #AirbnbWhileBlack. Lehane kicked into battle mode: He hired former attorney general Eric H. Holder Jr. to ­develop anti-bias policies, ­required hosts to pledge not to discriminate and promised to find a new rental for anyone who felt that they were rejected because of their race.

As the $30 billion company prepares to go public, Lehane, 49, is the architect of the effort to turn the Airbnb brand — “vacation rentals for hip millennials” — into a popular movement, one that is about giving a battered middle class the opportunity to rent out their homes. He is doing so amid mounting threats, not the least of which is a growing perception that tech platforms can facilitate more social harm than they do good.

“That was, for me, what we call a naked moment in politics,” Lehane said of the discrimination controversy, in an interview in Airbnb’s ultramodern and ever-expanding San Francisco offices. “When a candidate or an elected official will have that moment where their character is just basically tested. And there is no one out there propping you up. You have to make the right decision in that moment. And I think, for me, that was that moment for this company [and] community.”

He said Airbnb needed to do something more than a standard response, which wouldn’t have been true to a company whose brand, down to its heart-shaped logo, is about “belonging.”

Of course, not everyone agrees Airbnb has society’s best interests at heart. The company is accused of breaking scores of local laws that prohibit individuals from turning private homes into hotels and has been criticized for fueling an affordable-housing crunch.

“[Airbnb’s] attitude is, they do what they want — and litigation is a strategic tool,” said Ben Edelman, one of the authors of the Harvard study. “Silicon Valley believes you can still break the law and get away with it.”

Still, Lehane’s deals are evidence that Silicon Valley — a region once known for eschewing in-the-trenches warfare — has thoroughly embraced the real­politik. In a mere 17 months on the job, his team has persuaded officials in more than 100 localities to retreat from rules that would have been crippling for Airbnb, largely by borrowing tactics from the world of politics. Lehane, who had cut his teeth deflecting the controversies of the Clinton White House, has been campaigning city by city, striking compromises to get the company out of hot water.

Those deals have helped the home-sharing giant continue to grow, despite continuing opposition: Airbnb now has 1 million rooms available around the world — on par with Marriott ­International, the world’s largest hotel chain — and is expanding into tourism.

In many ways, Lehane is rewriting the political playbook for Silicon Valley. Nine years into the “sharing economy,” many see a new model of lobbying emerging. In it, Silicon Valley Utopianism — a signature blend of arrogance plus earnestness — has given way to calculated dealmaking with bureaucrats on every level of the political spectrum.

“There’s been a myth in Silicon Valley that you break and break things and get what you want. For some time, [Uber and Airbnb] did. I don’t think others will,” said Hemant Taneja, managing ­director of the venture capital firm General Catalyst, an Airbnb investor.

The central question is ­whether Lehane’s deals can amount to more than that. Can Airbnb, with its global ambitions and clout, represent the bigger idea Lehane is pushing — and can that idea withstand its growing contradictions?

A super PAC for Airbnb

Today, Lehane rarely wears the tailored Italian suits that he was known for during his days as a Washington operative. Now he favors the Silicon Valley uniform of jeans and Patagonia vests. He no longer plants political attacks in the news media the way he did in the Clinton White House or for Al Gore’s presidential campaign. Instead, he opts for TV spots that feature happy middle-class families promoting Airbnb.

The man who was fond of quoting boxer Mike Tyson — ­“Everybody has a game plan till they get punched in the mouth” — now says he “has channeled his inner millennial.”

But Lehane has not let go of his combative roots. In New York, he is funding a super PAC to support pro-Airbnb candidates. During his first few weeks on the job, in August 2015, he even reached out to former Army generals to ask for advice on how to wage war on a new scale.

Like Uber, which has leveraged both drivers and riders to lobby city officials in recent years, ­Lehane is part of an ascendant trend in Silicon Valley, a ­recognition that the region needs a new tool kit to engage the political process.

Software giants Apple, Google and Facebook long derided Washington, but they have become some of the biggest spenders of federal lobbying dollars in the past several years, focusing on intellectual property and patents.

Airbnb and Uber were part of a new wave of Silicon Valley companies that moved beyond the region’s core competence of software-building and into the physical world. They set up shop in cities without asking permission — or understanding how those businesses might conflict with existing laws. Eight years later, Uber and Airbnb have developed strategies that involve both ­compromises and red lines, an in-the-trenches approach where the ­results look different in each city. (The Washington Post’s ­owner, Jeffrey P. Bezos, is an investor in Airbnb.)

The tactics are now being embraced by other start-ups. Sequoia Capital, Silicon Valley’s top venture firm and an early Airbnb backer, is trying to replicate Lehane’s model with other companies. Over the past 18 months, Menlo Park-based Sequoia has begun hosting mayors at its Sand Hill Road offices and advising start-ups to hire political strategists and legal experts early on.

“We’ve learned that a lot of this is local — you can come up with one way to deal with regulators, but you must do it at a city-by-city, sometimes even a street-by-street or block-by-block basis,” said Alfred Lin, an Airbnb board member and Sequoia general partner. “We may have known this intellectually, but we didn’t quite [grasp] the complexity of it.”

Lehane’s effort has entailed a massive ground campaign. He has installed campaign managers in more than 100 cities around the world and visited almost all of them last year. The managers chime in every morning from all 24 time zones. He takes their calls on his 6:30 a.m. jogs through the Presidio, the tony San Francisco neighborhood overlooking the Pacific where he has lived for the past several years.

“I’m a big believer that you have to go to a place,” Lehane said. “Once you get on the ground, you can sort of decode the politics. You almost need an Enigma machine on some of this stuff.”

‘Drive them into the ground’

During his 20-year career as a political strategist, Lehane had been known for forceful and stunt-driven political theater. He orchestrated leaks about prosecutor Kenneth Starr from the Clinton White House and went on to serve as Gore’s press secretary. After Gore lost the presidential election, he brought his brazen style of politics in 2001 to California, where he took on contentious state ballot initiatives. Representing billionaire environmentalist Tom Steyer in his opposition to the Keystone XL Pipeline at a news conference, Lehane once had organizers break open vials of stinky sludge that had been collected during an oil spill.

In May 2015, he was recruited to Airbnb in a moment of crisis for the company. The ­home-sharing giant was fighting Proposition F, a San Francisco ballot initiative that would have ­restricted private home rentals to 75 nights a year. Lehane was on his way to coach his son’s Little League game when he got a call from Kim Rubey, Airbnb’s communications chief and a former ­Democratic operative.

Can you come in right away? she asked. Lehane, still in his sweatpants and jersey, rerouted his electric Fiat and headed down to SoMa, the start-up-filled San Francisco neighborhood where Airbnb is located. Rubey and the company’s general counsel, Belinda Johnson, expressed worries that the city was stepping up its ballot campaign against the company. They asked Lehane to sketch out what he would do.

At first, the executives were skeptical. “I said, ‘Here’s how you run a ballot campaign. You kick the s--- out of the other guy; you drive them into the ground,’ ” Lehane recalls. “I realized, as I was giving these answers, that they weren’t really resonating.”

Airbnb’s chief executive, Brian Chesky, didn’t want a slash-and-burn campaign that would demonize San Francisco officials, whose blessing they ultimately needed to operate, Johnson said. Lehane remembers thinking, “So, if you’re not going to go on TV saying there’s worms in the other guy’s burgers, what do you do?”

Still, Airbnb hired Lehane as a consultant. He was surprised to find out that there were 130,000 people living in San Francisco who had either stayed in an ­Airbnb or had been an Airbnb host. So he embarked on a campaign to mobilize them, knocking on doors, making calls, sending email blasts and targeted ads. The work paid off: Airbnb hosts who were contacted voted at a rate of 81 percent, enough, in an off-election year, to beat Proposition F by a small margin. Lehane became head of policy.

He has spent the past year trying to reproduce that strategy around the world. His campaign managers have set up “home-sharing clubs” in 100 cities, including Rome, Rio de Janeiro and Mexico City. Their members are Airbnb hosts who say they depend on the platform to stay in their homes, but they also see Airbnb as part of their identity as business owners. They write letters, op-eds and attend local meetings in support of the company. They organize street ­cleanings and toy drives. Together, they make the case that is central to Lehane’s campaign: Counter to the company’s early image as a service for ­couch-surfing, ­entitled millennials or its current image as a slick Silicon Valley company, Airbnb is a ­platform that helps sustain the middle class.

A history buff, Lehane describes the home-sharing clubs as a 21st-century version of the craftsman’s guilds that sprung up in Europe in the Middle Ages, an early example of workers banding together to protect their interests. He likes to say that Airbnb is “democratizing capitalism” and talks about the firm’s “social ­compact with cities.” Recently, the company published a position paper saying that senior citizens on pensions are the ­fastest-growing group of Airbnb hosts.

Sometimes, however, the ­company’s middle-class messaging seems at odds with itself: In the past year, Airbnb has also given away rentals to Kim Kardashian, Beyoncé and the supermodel Karlie Kloss.

Suits could open floodgates

But Lehane’s social compact goes only so far. For all his talk of responsibilities to cities, the company is arguing in court that it essentially has none. In lawsuits the company filed in San Francisco, Anaheim, Santa Monica, Calif., and New York, Airbnb argued that it isn’t responsible for illegal activity that takes place on its website.

The lawsuits rely on Section 230 of the Communications Decency Act, a 21-year-old law that is considered a pillar of the Web because it says that digital platforms, such as Twitter and Craigslist, can’t be held responsible for lawbreaking content posted by third parties.

While Airbnb has managed to settle its other cases, the ongoing San Francisco case is the most critical. There, the company is fighting a local ordinance that would subject it to steep fines if hosts don’t register with the city. The case is seen by legal experts as a crucial test of Section 230, and if Airbnb loses, it could open the floodgates to lawsuits ­elsewhere.

Edelman, the Harvard Business School professor, who is writing a legal brief supporting San Francisco, said that Airbnb is not an advertising platform like Facebook or Craigslist. “If Visa was processing charges for drug dealers, no law enforcement officer would hesitate to sue Visa,” Edelman said. “But Airbnb has managed to convince other local governments not to sue them. It’s a hell of a thing.”

Lehane’s stances have also infuriated some officials and ­affordable-housing advocates, who claim that Airbnb is reducing the supply of affordable housing and therefore fueling gentrification in such cities as Los Angeles, San Francisco and New York. They say a significant portion of Airbnb’s revenue are coming from professional renters — those who rent their apartments most of the year or have multiple listings — and that the company does next to nothing to kick out people who are creating a crunch on the local housing supply.

It’s hard to tell who is right. While some researchers have found that Airbnb is too small to have a widespread effect on urban housing markets, the home-sharing giant has declined to share enough data for a robust independent assessment to take place. (The company cites the privacy of its hosts.) That also makes it virtually impossible for officials to find the people breaking the laws and the commercial operators whose many listings may be driving up housing prices.

“Suppose your job is to try to find all the hosts who are noncompliant. Every city has someone with that job. How are you doing to do it? You can’t,” Edelman said. “[Airbnb’s] attitude is, they do what they want.”

Of course, many people who rent out their homes ­commercially — even if they are breaking local housing laws by doing so — aren’t aspiring to be the next Marriott. They’re ­middle-class people trying to make an extra buck. They may be fighting gentrification even as they are fueling it. And Lehane, who has worked for Democrats, unions and middle-class defenders throughout his career, has firmly decided that he’s not going to go after them.

In recent months, he has extended olive branches in San Francisco and New York, where resistance from affordable housing advocates has been fiercest, by notifying hosts that they should be renting out only their own home. He has also booted several thousand hosts from Airbnb. But the efforts are largely pro forma. He said building goodwill in cities is slower and more expensive than litigation, and that lawsuits are a “last resort.”

‘Trying to win the right away’

It’s not clear whether Lehane will ultimately win his ground war.

If Airbnb loses the San ­Francisco case — by far its most formidable legal threat — it could open the company up to a spate of lawsuits in other jurisdictions. In addition, a painful compromise that Lehane swings in one city could open the floodgates in ­another.

Lehane said his goal is less about winning any individual deal, lawsuit or campaign than it is about getting the public to rally around a bigger idea — to believe that this relatively new and ­disruptive form of economic ­activity, home-sharing over the Internet — squares with society’s greater aspirations.

“As a [political] consultant, you’re being judged by whether you win those battles. Not ­necessarily the bigger war,” he said. Here, “you’re really trying to win the right away.”