SAN FRANCISCO — Gerald Harris was walking along Ocean Beach, the blustery coastline at the western edge of the city, when he passed Danny Glover, a star of Hollywood action movies and a San Francisco native. The men exchanged glances.
“We were the only two black people in the area,” Mr. Harris said.
San Francisco was once a national beacon of African-American culture, home to a thriving jazz scene that had so many clubs it was known as the Harlem of the West. But these days, blacks say they take notice when they see another African-American in affluent and middle-class neighborhoods.
The jazz clubs of the Fillmore neighborhood have been replaced with upscale shops. Marcus Books, a cultural anchor of the black community and one of the first bookshops in the nation to focus on African-American topics, closed in 2014. Other black landmarks that have long since disappeared are commemorated with remembrances embedded in the sidewalk like tombstones to a forgotten culture.
The decline has been steady and noticeable. One of seven residents was black in 1970. Today, it is nearly one of 20, with most of the city’s 46,000 blacks living in public housing.
“My prediction is 10 years from now, we won’t have 20,000 blacks in this city,” said the Rev. Amos C. Brown, the pastor of Third Baptist Church, a historically black church founded in 1852.
While San Francisco residents agree that the loss of black culture is palpable, there is disagreement over what to do about it. City officials say they are trying to retain the remaining black population, largely through expanding and improving public housing, and want to lure more affluent blacks to the city. They are also confronting accusations of racial profiling by the police force, which has spurred protests throughout the city.
Yet one of the city’s most prominent African-Americans, Willie Brown, a former mayor and former speaker of the California State Assembly, said he did not believe the shift could be reversed. There is no point in trying to engineer the city’s ethnic population, he said.
“I don’t think I would put a whole lot of time and energy into doing anything,” Mr. Brown said, “except making sure there’s equal access and equal opportunity and equal resources.”
He called the current mix — with whites, Asians and Latinos making up the largest segments of the population — a “new reality.”
The reasons for the migration are in large measure economic: Skyrocketing real estate prices fueled by high-paying tech jobs have priced out middle-class residents of all ethnicities. But the exodus was also accelerated by a domino effect of black businesses and families moving away, many of them to Oakland and other cities along the East Bay.
When black communities, which were splintered into three areas in San Francisco, lost their barber shops, restaurants and clubs, they lost their centers of gravity, according to Mr. Brown. Black residents moved to places where they felt more “comfortable socially,” he said.
The tech industry, the motor of San Francisco’s economy in recent years, has accelerated the decline. The tech industry skews white and Asian. John William Templeton, a local historian and an advocate for greater black participation in the industry, said it was disappointing that blacks were not more involved in one of America’s most successful industries.
Around 1 percent of employees at tech companies in the Bay Area are black, down from 4 percent in 1998, according to Mr. Templeton.
The shift was also partly encouraged by what is now recognized as an extensive and misguided city policy of eradicating what was called “urban blight.” Thousands of homes in black neighborhoods were razed in the name of redevelopment from the 1950s to the 1970s. Theodore Miller, an aide to Mayor Edwin M. Lee, called it a “terrible undertaking that had catastrophic consequences.”
The final draft of a city-commissioned report, published in January, said redevelopment benefited prominent members of the business community whose “real motivation was the replacement of low-value ‘slums’ with high-value commercial and residential development.”
The city is by no means empty of African-Americans, especially in the business district; many blacks commute to work from other cities in the Bay Area.
Still, Mr. Harris said he often found that he was the only African-American in restaurants or at the Commonwealth Club, where he helps organize seminars on science and technology.
Frederick E. Jordan, a business leader who talks about the need for a “Marshall Plan” to woo more blacks to the city, says “there are no jobs and no contracts” for blacks.
“Our backs are against the sea; we’re almost out,” said Mr. Jordan, who owns an engineering firm and is the chairman of the San Francisco African American Chamber of Commerce.
“We have to rebuild our African-American middle class,” said Mr. Miller, the mayor’s aide. The majority of blacks who remain are disproportionally poor, with median incomes for blacks at $27,000 compared with $89,000 for whites, a disparity twice as large as the national average.
Blacks who remain have been subject to racial profiling by the police, according to the public defender’s office, and a recent report commissioned by the city cited a host of actions by the police against blacks that appear to be discriminatory.
The report found that while African-Americans make up about 6 percent of the city’s residents, they constituted about 40 percent, 20 of 51, of the victims of officer-involved shootings from January 2010 through July 2015. In addition, the study found evidence of racial disparities in the rate of police stops and searches of African-Americans.
Those racially charged shootings, including of a black man and woman, forced the police chief, Gregory P. Suhr, to resign in May.
From the days of the gold rush, San Francisco was a place of opportunity for pioneering blacks, as it was for Jews, Italians, Irish and other ethnic groups. The city’s black population was small until around World War II, when tens of thousands of blacks migrated from the South to work in shipyards and other wartime jobs. The African-American population increased by nearly 800 percent in the 1940s and reached its peak around 1970, when 13 percent of the city was black.
San Francisco also played a role in the civil rights movement. In 1968, black students at what was then San Francisco State College (now San Francisco State University) held a prolonged strike that led to the creation of the nation’s first black studies program, a campaign chronicled in the recent documentary “Agents of Change.”
Mr. Glover, who took part in the protests as a student, said the black exodus from the city made him “sad and angry.”
The larger question, he said, is whether San Francisco is becoming an enclave for the rich.
“It’s a question about who we are and our responsibility to build our communities,” he said, “and not just based upon who has the ability to pay.”
The frustration is keenly felt among those whose neighborhoods have lost their core. Many say they feel like strangers in their own city.
“You get the feeling that people are thinking, ‘You’re still here?’” said Barbara Gainer, a probation officer and a jazz singer. She lives in the western reaches of the city, a neighborhood that was once predominantly black but now is mostly Asian-American, a segment that now makes up 34 percent of the city’s population, up from 13 percent in 1970.
Ms. Gainer says she is regularly asked if she wants to sell her house; her mailbox fills up with solicitations. The inquiries were flattering at first because they reminded her of the value of her property, but now she feels singled out. She remembers one couple in particular who approached her four or five times about selling. She tried to dissuade them.
“I said: ‘Even if I sold you my house and you gave me this big price, why would I do that? Where would I live?’”
The reply stunned her: “You should go to Antioch. That’s where your people go.”
Antioch, a city about 50 miles northeast, has a sizable African-American population.
At Mr. Brown’s Third Baptist Church, attendance has been steadily declining; on a recent Sunday, around 150 parishioners worshiped in a sanctuary that seats 1,100. “We pray that we would never be cut flowers, that we would always have roots,” Mr. Brown told the congregation.
Mr. Brown then told the story of hearing a radio program lamenting the looming extinction of a type of butterfly.
“And yet,” he said, “we don’t have the basic compassion and common sense to realize that blacks are an endangered species in the city of San Francisco.”