A man was fatally shot in a brazen attack Sunday afternoon across the street from a San Francisco police station in the Western Addition.

The gunman opened fire at 2:48 p.m., hitting the victim, who was in the passenger seat of a white Dodge sedan that was leaving a McDonald’s parking lot on Fillmore Street and Golden Gate Avenue, said police Sgt. Anthony Manfreda.

The victim scrambled out the driver’s side and ran a few steps, but collapsed on the sidewalk near a bus stop, Manfreda said. Paramedics took him to San Francisco General Hospital, where he later died.

Police were interviewing the driver, who was not injured, and other witnesses. Detectives were also looking at video surveillance recordings.

The attacker, who witnesses described as a young man wearing dark clothing, then ran through the parking lot and got into another car, which sped east on Golden Gate toward Webster Street, Manfreda said.

Police didn’t immediately know if the attack was a “random or targeted shooting,” Manfreda said. The gunman had approached the passenger side and looked inside before firing, he said. The car could not move because of traffic and was “a sitting duck,” he said.

The shooting happened across the street from Northern District Police Station. The gunfire could be heard around the block at a nearby church, and the sounds sent bystanders running for cover. One woman said she and her child had just ordered food, but they ran out of the restaurant in fear when shots rang out.

Sam Lin, who works at another restaurant across the street, didn’t see the shooting, but ducked behind his front counter when he heard five or six shots. He said officers ran to the scene almost immediately, but said having the police station on the same block doesn’t deter crime in the neighborhood.

“They don’t fear the cops,” Lin said.

As investigators examined multiple bullet holes punched through the car’s door and window, Manfreda said the police station alone is “not a deterrent.”

Manfreda called the homicide brazen because “it happened in the middle of the afternoon, and there was a lot of pedestrian and motor vehicle traffic. Unfortunately, it’s not the first time it’s happened.”

Angelica Casas, Benny Evangelista and Evan Sernoffsky are San Francisco Chronicle staff writers. Email: bevangelista@sfchronicle.com, esernoffsky@sfchronicle.com Twitter: @ChronicleBenny, @EvanSernoffsky