They came for the music, the mind-bending drugs, to resist the Vietnam War and 1960s American orthodoxy, or simply to escape summer boredom. And they left an enduring legacy.
This season marks the 50th anniversary of that legendary "Summer of Love," when throngs of American youth descended on San Francisco to join a cultural revolution.
Thinking back on 1967, Bob Weir of the Grateful Dead recalls a creative explosion that sprouted from fissures in American society. That summer marked a pivot point in rock-and-roll history, he says, but it was about much more than the music.
'There was a spirit in the air.'
"There was a spirit in the air," said Weir, who dropped out of high school and then helped form the Grateful Dead in 1965. "We figured that if enough of us got together and put our hearts and minds to it, we could make anything happen."
San Francisco, now a hub of technology and unrecognizable from its grittier, more freewheeling former self, is taking the anniversary seriously. Hoping for another invasion of visitors -- this time with tourist dollars -- the city is celebrating with museum exhibits, music and film festivals, Summer of Love-inspired dance parties and lecture panels. Hotels are offering discount packages that include "psychedelic cocktails," "Love Bus" tours, tie-dyed tote bags and bubble wands.
The city's travel bureau, which is coordinating the effort, calls it an "exhilarating celebration of the most iconic cultural event in San Francisco history."
One thing the anniversary makes clear is that what happened here in the 1960s could never happen in San Francisco today, simply because struggling artists can't afford the city anymore. In the Haight-Ashbury neighborhood, which was ground zero for the counterculture, two-bedroom apartments now rent for $5,000 a month. San Francisco remains a magnet for young people, but even those earning six-figure Silicon Valley salaries complain about the cost of living.
In the mid-1960s, rent in Haight-Ashbury was extremely cheap, Weir, now 69, told The Associated Press.
"That attracted artists and bohemians in general because the bohemian community tended to move in where they could afford it," he said.
During those years, the Grateful Dead shared a spacious Victorian on Ashbury Street. Janis Joplin lived down the street. Across from her was Joe McDonald, of the psychedelic rock band Country Joe and the Fish.
Jefferson Airplane eventually bought a house a few blocks away on Fulton Street, where they hosted legendary, wild parties.
"The music is what everyone seems to remember, but it was a lot more than that," said David Freiberg, 75, a singer and bassist for Quicksilver Messenger Service who later joined Jefferson Airplane. "It was artists, poets, musicians, all the beautiful shops of clothes and hippie food stores. It was a whole community."
The bands dropped by each other's houses and played music nearby, often in free outdoor concerts at Golden Gate Park and its eastward extension known as the Panhandle. Their exciting new breed of folk, jazz and blues-inspired electrical music became known as the San Francisco Sound. Several of its most influential local acts -- the Grateful Dead, Jefferson Airplane, Big Brother and the Holding Company, which launched Joplin's career -- shot to fame during the summer's three-day Monterey Pop Festival.
One song in particular served as a national invitation to hippies across the land. "San Francisco (Be Sure to Wear Flowers in Your Hair)," written by John Phillips of the Mamas & the Papas and sung by Scott McKenzie, came out in May 1967. It bolted up the charts and was used to help promote the Monterey festival that June.
"Every fantasy about the summer of '67 that was ever created -- peace, joy, love, nonviolence, wear flowers in your hair and fantastic music -- was real at Monterey. It was bliss," said Dennis McNally, the Grateful Dead's longtime publicist and official biographer who has curated an exhibit at the California Historical Society that runs through Sept. 10.
The exhibit, "On the Road to the Summer of Love," explains how that epic summer came about and why San Francisco was its inevitable home. McNally uncovered 100 photographs, some never seen publicly, that trace San Francisco's contrarian roots to the Beat poets of the 1950s, followed by civil rights demonstrations and the Free Speech Movement at the University of California, Berkeley in the early 1960s.
The national media paid little attention to San Francisco's psychedelic community until January 1967, when poets and bands joined forces for the "Human Be-In," a Golden Gate Park gathering that unexpectedly drew about 50,000 people, McNally said. It was there that psychologist and LSD-advocate Timothy Leary stood on stage and delivered his famous mantra: "Turn on. Tune In. Drop out."
"After the media got hold, it just exploded," McNally said. "Suddenly, a flood descends on Haight Street. Every bored high school kid -- and that's all of them -- is saying, `How do I get to San Francisco?"'
An exhaustive exhibit at San Francisco's de Young museum, "The Summer of Love Experience," offers a feel-good trip back in time. There's a psychedelic light show, a 1960s soundtrack and galleries with iconic concert posters, classic photographs and hippie chic fashions worn by Joplin, Jerry Garcia and others. It runs through Aug. 20.
But that summer's invasion carried a dark cloud. Tens of thousands of youths looking for free love and drugs flooded into San Francisco, living in the streets, begging for food. Parents journeyed to the city in search of their young runaways. An epidemic of toxic psychedelics and harder drugs hit the streets.
"Every loose nut and bolt in America rattled out here to San Francisco, and it got pretty messy," Weir said.
The longtimers saw it as the end of an era, but one that shaped history.
"We created a mindset that became intrinsic to the fabric of America today," said Country Joe McDonald, now 75. "Every single thing we did was adapted, folded into America -- gender attitudes, ecological attitudes, the invention of rock and roll."
Half a century later, McDonald, who lives in Berkeley, feels the rumblings of history repeating itself.
UC Berkeley is again at the center of a free speech debate, albeit of a different nature. Discontent with the U.S. government and President Donald Trump has stirred the largest protests he's seen since the Vietnam War. In the women's marches across America, he felt echoes of the Summer of Love.
"I think there's a similarity," McDonald said, drawing a parallel to the massive anti-Trump turnout marked by nonviolence, playful pink protest hats, creative signs and a determination to change the country's political course. "Both were about saying goodbye to the past and hello to the future."