The number of needles that once piled up in BART’s downtown San Francisco stations — detritus from a heroin and speed epidemic that’s choked city streets and seeped into the transit system — is suddenly on the decline.

It’s not necessarily cause for celebration, though, as one driving factor is an increase in the use of the deadly drug fentanyl, which addicts are more likely to smoke.

A year ago in July, custodial workers at BART picked up 4,197 needles from the Civic Center and Powell stations — 2,678 at Civic Center and 1,519 at Powell. The sharp objects were so prevalent that one woman reported getting pricked by a hypodermic needle wedged in a seat cushion.

By May of this year the numbers had fallen dramatically, to 585 needles from the two stations combined. Workers retrieved 419 at Civic Center and 166 at Powell.

The drop signifies a remarkable change for stations that only a year ago were lined with slumped-over drug users. BART’s staff and outreach teams cite various factors, including the closure of an infamous Civic Center hallway, ramped-up police patrols throughout the stations, and kiosks installed downtown and throughout United Nations Plaza near the BART stairwells.

But another explanation is that people are shifting from heroin to the synthetic painkiller fentanyl, according to officials.

“We caught someone smoking fentanyl on a train the other day,” said BART police Officer Keith Garcia, who is president of the transit system’s police union. He said the new drug of choice is “all around town,” so it’s become more visible in places like the stairway to United Nations Plaza, where a group of people was smoking a substance off strips of aluminum foil on a recent Tuesday evening.

Data from San Francisco’s Department of Public Health tell a slightly different story on city streets. The number of syringes littering roads and sidewalks or deposited in kiosks soared from 2017 to 2018 — from 3.3 million to 3.8 million. This year it appears to be dipping, with just over 1 million syringes collected from the beginning of January through the end of April, on track for a little more than 3 million by the end of the year.

Even as cleanup efforts improve, outreach workers have noticed a change in the drug landscape. It’s borne out in overdose figures that show fentanyl surging as a killer in San Francisco. Last year the potent narcotic caused 57 deaths, compared with 39 attributed to heroin and 53 to prescription opioids such as oxycodone and codeine.

“At the beginning of last summer we saw fentanyl shift from being a contaminant of tar (heroin) to being the drug that people were choosing,” said Ro Giuliano, director of the San Francisco AIDS Foundation Harm Reduction Center. The group runs a clinic on Sixth Street where people can get clean syringes, HIV and hepatitis C testing, or containers of life-saving Narcan nasal spray to reverse the effects of an overdose.

Transit officials, social service workers and medical experts are struggling to interpret the trend. Fentanyl, though deadly, has some attractive features. Because it’s so powerful, users take smaller amounts to get high or tamp down withdrawal symptoms, so it can be cheaper than heroin. Smoking fentanyl — heating a small amount on a piece of foil and inhaling the fumes — can also be just as effective as injecting heroin, and many users prefer a method that doesn’t require stabbing a vein.

“When folks switch from injection to smoking, it prevents vein damage, abscesses and other soft tissue infections,” as well as the spread of HIV and hepatitis, Giuliano said. She and other outreach providers have begun handing out foil along with clean syringes.

Still, the reasons for the rise in fentanyl may be even simpler: After devastating the East Coast, it migrated west and flooded the Bay Area market. And people bought it.

“It seems like the supply has changed, so the drugs people are purchasing have changed,” Giuliano said.

That turn in the addiction world coincides with BART’s effort to shoo drug users and transients out of the downtown stations and plazas, which are also the portal to San Francisco’s tourist district and its gilded City Hall.

In November, BART closed the Civic Center entrance at Eighth and Market streets to make room for a new traction power substation in a space where people once congregated to shoot up heroin and speed. Then in April, the agency began a crackdown in which police and yellow-vested managers swarm the downtown stations at dawn, then stand at the fare gates for hours. The extra patrols are still in force, intimidating would-be fare cheats and staving off other forms of crime.

During the blitz, BART’s needle pickup count plunged. Its once-squalid floors and tiled walls now gleam, and a perfume of disinfectant wafts through the corridors.

Yet BART hasn’t stanched its drug use problem. While scenes of people sticking needles in their arms became more rare on the station platforms and concourses, heaps of burnt foil with drug residue started turning up in the stairwells. Upstairs in the plaza, people smoke while hiding beneath blankets and sweaters. When police officers and station agents arrive to work at 4 a.m., their debris is “literally everywhere,” Garcia said.

“Everyone is doing fentanyl,” said Ronnie Daniels, who was sitting with his two dogs outside the Main Library on Wednesday morning. Across the street, United Nations Plaza was abuzz with food trucks and farmers’ market vendors.

Though Daniels said he personally eschews hard drugs, his friends who use substances have made the switch.

A man sitting nearby, who gave his name as Sal, had a bag of powdered fentanyl stashed in a fanny pack. He said he smokes or snorts it, or occasionally uses prescription patches that he buys on the underground market. In medical settings patients sometimes absorb the drug through patches applied to the skin, or by sucking on hard candies dosed with fentanyl.

“I’ve never been a fan of needles,” Sal said.

Some BART riders said they’ve seen the trappings of injection drug use slowly disappear. Others were skeptical.

“I’ve noticed a small difference,” said Jay Lopez, a Hayes Valley resident who was standing on the Civic Center platform Friday morning.

Kevin Tokunaga shook his head dubiously. He’d traveled from Torrance (Los Angeles County) to visit the Bay Area for the Fourth of July weekend.

“I saw some syringes on the tracks in Oakland yesterday,” Tokunaga said. “It’s really gross.”

Mary Howe, executive director of the Homeless Youth Alliance, was surprised when she saw signs of a new epidemic in San Francisco: charred foil and syringes cut into straws, to suck fentanyl from the foil.

Her Haight neighborhood organization — one of several that partner with the city to do a roaming needle exchange — started handing out foil a couple months ago. The idea: reduce the risk of overdose by encouraging people to smoke rather than inject.

While nonprofits scramble to address the new drug wave, officials who thought BART had turned the corner on needles are now confronting something that seems more sinister and dangerous.

“I definitely see people smoking a substance off of tinfoil — particularly on the stairs leading out of the station,” said BART board President Bevan Dufty. “Periodically we’ll see it on the trains, which is disruptive and frightening, and understandably freaks people out.”

He’s still confident that narcotic use is going down overall at BART.

“We have more cleanings, elevator attendants, police patrols ... and the Department of Public Health’s safe disposal kiosk in United Nations Plaza,” he said. “The bottom line is riders are seeing fewer needles. And that’s encouraging.”

Rachel Swan is a San Francisco Chronicle staff writer. Email: rswan@sfchronicle.com Twitter: @rachelswan