Residents of a quiet Dublin neighborhood were shocked Monday to learn that a police officer shot and killed an 18-year-old man Sunday night after he allegedly attacked an officer with a baseball bat.

The shooting happened at a condominium on Dublin Meadows Street about 6:15 p.m. Officers were called to investigate reports by a woman that her brother, Oscar Herrera, was having a mental breakdown and may have assaulted his mother, police said.

Officers arrived at the ground-floor unit and were met at the front door by Herrera holding a baseball bat, said Dublin Police Chief Tom McCarthy.

Herrera used the bat to strike an officer in his right hand, which was holding his gun, the chief said. "He immediately pulled the bat up in an upward motion like he was going to do a downward swipe with the baseball bat," McCarthy said.

The officer, fearing for his safety, fired four shots at Herrera, the chief said.

The night before he was shot, Herrera, while possibly under the influence of methamphetamine or some other drug, got into a fight with a friend in Livermore and was "actually threatening to eat his friend," said McCarthy. Livermore police reported shocking the bloodied Herrera with a stun gun before taking him to a hospital.

But on Sunday, he left the hospital against a doctor's advice and returned home with his mother, police said. Investigators are awaiting the results of toxicology tests. Herrera has a criminal history for weapons and drug possession, assault and resisting arrest, police said.

Neighbors said Herrera, who was pronounced dead at the scene of the shooting, was a student at Foothill High School in Pleasanton. His family could not be reached Monday, and no one answered the door of the home.

"My heart is just broken for the family," said Shari Vernor, who lives above the unit where the shooting happened and said violence is virtually unheard of in the Mediterranean-style Alamo Creek Meadows complex off Amador Valley Boulevard.

Bloodstains were still visible Monday on the front door and on the sidewalk at the home, where Herrera lived with his older sister and their mother, according to Vernor. She said she heard a woman on Sunday evening yelling, "Don't shoot him," followed by gunfire.

Herrera "has always been really friendly and says hi to me," she said.

The name of the officer who fired his weapon was withheld. He suffered non-life-threatening injuries and was placed on paid administrative leave pending investigations by police and the Alameda County district attorney's office.

The incident is the third fatal officer-involved shooting in the Bay Area in recent months in which police shot and killed people they said were armed with baseball bats.

Last month, Santa Clara police shot and killed a suicidal 53-year-old woman after she charged at them with an aluminum bat, police said. In February, Alameda County sheriff's deputies - who also patrol Dublin under contract - shot and killed a 61-year-old man in Castro Valley after he allegedly swung a bat at them.