The shooting triggered a massive manhunt and evacuations of an apartment complex next to the station, but no suspect was in custody as of Thursday morning.
The incident occurred at about 2:48 p.m. at the station at 501 West Lancaster Boulevard, a sheriff's spokesperson said.
Authorities immediately set up a perimeter in the area and launched a massive search, focused on the nearby four-story apartment building.
The injured deputy was conscious and breathing after being transported to a hospital by ambulance, officials said.
Sheriff's department officials later identified the deputy as Angel Reinosa, a 21-year-old patrol trainee who had been with the department about a year. He was walking to his car in the employee parking lot when he was shot from a four-story building overlooking the station.
He was heard calling in the shooting over emergency radios.
LANCASTER SHOOTING: Wounded deputy calls in own shooting in dramatic audio
"I have taken shots from the north of the Lancaster helipad," the deputy is heard saying over the radio. "I think I'm hit in the right shoulder."
He was treated and released from the hospital and did not need surgery, as his ballistic vest absorbed the brunt of the bullet.
"A sniper took out one of our deputies," Lancaster Mayor R. Rex Parris said. "And the only reason that deputy is alive is because he had his vest on."
"He was getting ready to take that vest off. Had he done so, it would've been a much more tragic situation."
Parris visited the deputy in the hospital.
"He's in a lot of pain but he's going to be OK," Parris said. "He took a bullet here but he had his vest on, so it deflected up and hit his shoulder."
Parris said it appears the shooting was a random act and not one directed at that specific deputy.
"It was not targeted on this specific deputy. It was any deputy would do."
Initial reports indicate two shots were fired from a four-story residential building near the sheriff's station. The residential building is next to a facility that provides mental-health treatment.
Although Parris said that the apartment building was for housing mental-health patients, a spokesperson said that is not the case - that the apartments and the mental-health treatment are separate buildings and unrelated operations and the housing is not specifically for those receiving mental-health treatment.
Residents of the building told Eyewitness News there are some mental-health patients who live in the complex, but the building is not specifically designated for that purpose.
The building is low-income government subsidized housing. Hundreds of residents were evacuated as deputies went floor-to-floor to search for the shooter.
Some residents say it is not a safe place to live.
"They let people live in our apartment complex who have mental illness," said Terrisa McGhee, who lives in the apartment complex. "It's kind of scary because there's no security onsite 24 hours. Management is never here when things happen. The cops are in there constantly. So its not a surprise."
Small teams of heavily armed deputies, some wearing tactical gear, were seen going from vehicle to vehicle in a parking structure near the sheriff's station. The search was being conducted amid 105-degree temperatures in Lancaster.
The public was urged to avoid the area bounded by Lancaster Boulevard, Sierra Highway, West Jackman Street and Beech Avenue.
Later Wednesday evening, two people were taken into custody, but officials said they had just been uncooperative with the search and evacuation orders, and were not considered suspects.
The search of the complex was ended before 11 p.m. with no suspect in custody and residents were being allowed back into their homes.
Sheriff's department officials were just grateful that the deputy had avoided more serious injury.
"He's been treated, he's doing well in high spirits," said sheriff's Capt. Todd Weber. "His family's with him. We expect he'll be fine, full recovery."