SAN RAFAEL, Calif. — For more than a decade, few places in the nation were associated with anti-vaccine movements as much as Marin County, the bluff-lined peninsula of coastal redwoods and stunning views just north of San Francisco.

This corner of the Bay Area had become a prime example of a highly educated, affluent community with low childhood vaccination rates, driven by a contingent of liberal parents skeptical of traditional medicine. Marin was something of a paradox to mainstream Democrats, and often a punching bag. In 2015, during a measles outbreak in California, the comedian Jon Stewart blamed Marin parents for being guilty of a “mindful stupidity.”

But Marin is the anti-vaccine capital no more.

In the pandemic age, getting a Covid-19 shot has become the defining “vax” or “anti-vax” litmus test, and on that account, Marin County has embraced vaccines at rates that surpass the vast majority of communities in the nation. It comes after public health efforts to change parents’ opinions, as well as a strict state mandate that students get vaccinated for childhood diseases.

And as the nation has grown more polarized, Marin residents are less comfortable wearing the “anti-vax” label increasingly associated with conservatives. Americans who identify as Democrats are more than twice as likely to be vaccinated and boosted against Covid — and Marin County is one of the bluest enclaves in America.

“It kind of became the cool thing to do to get vaccinated,” said Naveen Kumar, physician-in-chief for Kaiser Permanente San Rafael Medical Center.

Dr. Kumar said some Marin parents who were hesitant about the vaccines have been persuaded by their children’s enthusiasm, which he has witnessed among his teenage son and his friends. “I could hear him talking about, ‘Can you believe there’s this kid in my class and he’s not vaccinated?’ he said. “You almost become a little bit of an outcast if you’re not vaccinated.”

Among children 5 to 11, 80 percent in Marin County have both of their Covid shots, more than double the statewide or national rates. The rate among those under 5 is more than five times the nation’s.

Given that a fifth of elementary-school-age children here still have not gotten the vaccines, it is not clear that Marin holdouts have changed their minds. But anti-vaccine parents no longer feel as empowered to voice their opinions. The mood shift was pointedly captured by a local columnist, who declared in January, “Unvaccinated? You’re not welcome in Marin.”

Julie Schiffman, 50, doesn’t have her Covid shots; she said she believes vaccines would aggravate her many autoimmune conditions. Because she is unvaccinated, she has been excluded from Marin home-schooling gatherings that she had attended for years, even though parents were previously unconcerned with whether anyone had their shots. For the first time, she said, she feels as though people here despise her on principle.

Ms. Schiffman said that when her sons were young, she decided not to have them vaccinated because of similar concerns about vaccine side effects. Their vaccination status was never an issue for student enrollment because she home-schools them.

But because of the social pressure to be vaccinated against Covid, the boys got their Covid shots last year. Her 13-year-old “wanted to be first in line,” Ms. Schiffman said. “I’m the only one in my family who did not.”

Across the Golden Gate Bridge from San Francisco, Marin County has strikingly beautiful landscapes and lush, wooded neighborhoods. The region was once largely made up of farms and small communities, with locals dedicated to living off the land.

The county became more bohemian in the 1960s and 1970s as the counterculture diaspora arrived seeking to get away from the chaos of San Francisco. The Grateful Dead lived in a commune here in 1966, and Otis Redding wrote “(Sittin’ On) The Dock of the Bay” while staying on a houseboat off Sausalito.

Marin is also a bastion of wealth, with California’s highest median joint income in 2019 at $178,755. On weekends, luxury cars sneak past cyclists atop high-end bikes on roads heading toward the great Pacific. Before he became the Democratic governor of California, Gavin Newsom lived with his family on a hillside in Marin — with three Tesla vehicles in his driveway, The New Yorker once wrote.

In 2011, the percentage of kindergartners in Marin County who had all of their required shots — 78 percent — had fallen to fifth lowest among California’s 58 counties. Whooping cough outbreaks fueled by low vaccination rates were sending young children to the hospital.

Around that time, Matt Willis was working as an epidemiologist for a branch of the U.S. Centers for Disease Control and Prevention that responds to global disease outbreaks. In 2010, he had been sent to Haiti after a massive earthquake there severely limited access to vaccines.

The following year, he was dispatched to his hometown in Marin County, where he was perplexed by what he found. “In other places I’d been working on vaccines, it was purely just logistical and operational, and here it was a matter of belief, which was a much harder nut to crack.”

Dr. Willis left the C.D.C. and in 2013 took over as Marin County’s health officer, and he was intent on figuring out why relatively few parents were vaccinating their children.

He surveyed the parents of thousands of kindergartners to understand what their vaccine concerns were. On the list were autism, ingredients in vaccines and the speed at which babies are administered dozens of shots. A 1998 study that purported to connect the measles, mumps and rubella vaccine with autism was debunked and retracted — but only after propelling the anti-vaccine movement, particularly among parents skeptical of traditional medicine and pharmaceutical companies.

Dr. Willis began public health campaigns to specifically address those fears and primed local pediatricians to have those conversations too. His efforts got a boost when, in late 2014, a measles outbreak erupted at Disneyland, drawing greater attention to unvaccinated children. When cases spread to Marin County, its low vaccination rates became a glaring example in California.

At the same time, Rhett Krawitt, then a 6-year-old living in Corte Madera, was battling leukemia and was too medically fragile to be immunized against measles. An infection could kill him. Sitting in their backyard this summer, home to a thriving vegetable garden and pickleball court, his father, Carl Krawitt, recalled how Rhett’s oncologist urged them to ask the parents of classmates to get their children vaccinated.

When they did, it seemed as though parents who had avoided vaccines hadn’t fully grasped that there could be real consequences for other people, Mr. Krawitt said. “Once they understood it, they went out and got vaccinated,” Mr. Krawitt said.

Rhett, then a towheaded boy with a round face, spoke at the State Capitol to urge lawmakers to pass a stricter vaccination requirement that was sparked by the measles outbreak. The law, which requires that all California children receive vaccines to attend school, passed in the summer of 2015. Vaccination rates subsequently increased in Marin County and statewide.

“A lot of different building blocks led up to a big change,” said Rhett, now a lanky 14-year-old who has since gotten all of his vaccines for childhood diseases and Covid-19. He spends far more time thinking about sailing, his favorite hobby, these days.

By the 2019-20 school year, Marin County’s childhood vaccination rate was up to nearly 95 percent, in the middle of the pack statewide instead of near the bottom.

And then the pandemic hit.

The county was one of the first areas in the nation to implement a stay-at-home order in March 2020. Adherence to masking and social distancing here was high in the early days of the pandemic. And, locals say, the benefits of a vaccine quickly became obvious.

Dr. Willis also capitalized on his years of combating vaccine hesitancy. Anticipating that Marin parents might resist vaccinating their children, he decided to administer Covid vaccines for ages 5 to 11 largely at schools.

He hoped that campus-based events — where staff played music, decorated with balloons and even brought comfort dogs — were less intimidating than going to a doctor’s office. Within the first two weeks of the vaccine rollout for children ages 5 to 11, 40 percent of Marin County kids in that age group had gotten their first Covid vaccine dose, half at the school events.

Now, Marin County’s Covid vaccination rate among all residents is 91 percent, compared with 68 percent nationwide.

The county has also shed its reputation as an anti-vaccine haven in part because of how much vocal resistance has taken root elsewhere. Marin County was once faulted for having a childhood vaccination rate of 78 percent. Now, almost every county in America has a lower Covid vaccination rate among children.

The anti-vaccine movement used to be a place where the left met the right, but increased polarization during the pandemic has made such a combination difficult to sustain, said Jennifer Reich, sociology professor at the University of Colorado Denver and the author of “Calling the Shots: Why Parents Reject Vaccines.”

“When we start to see such vastly different sources of information about what the risks of infection of Covid are, you start to see people making wildly different decisions in their life,” Ms. Reich said. “The vaccine and scientific expertise has become politicized.”

Ms. Schiffman said her children got the Covid vaccine because they wanted to be able to go to camp, concerts and the climbing gym with their friends. Without her shots, she frequently can’t get into restaurants and other places because they require that patrons show vaccine cards. She said she might think about moving if life became even tougher to navigate without proof of vaccination.

“I will never ever put a vaccination in my body ever again,” Ms. Schiffman said. “Would that mean splitting up my family? It could.”

The culture change in Marin has been so dramatic that many new parents struggle to understand how the county earned its infamous reputation.

Dana McRay, a Corte Madera resident who recently took her 3- and 5-year-old daughters to get their Covid vaccines, said she has “never met anyone who was anti-vax, or at least who talks about it.”

In a local parenting Facebook group Ms. McRay is in, a mother recently asked if anyone would have a play date with her unvaccinated kids. “All of the other parents told her there was a separate Facebook group for anti-vax parents, and she should take her request there.”