The 31-year-old female deputy and 24-year-old male deputy both underwent surgery, Sheriff Alex Villanueva said in a late-night news conference.
Both graduated from the academy 14 months ago, he said.
The deputies were shot while sitting in their patrol car at a Metro rail station and were able to radio for help, the sheriff said.
Mr Villanueva, whose department has come under fire during recent protests over racial unrest, expressed frustration over anti-police sentiment as he urged people to pray for the officers.
“It pisses me off. It dismays me at the same time,” he said.
The department shared video of the shooting in a Twitter post showing a person open fire through the passenger-side window of the patrol car.
“The gunman walked up on the deputies and opened fire without warning or provocation,” the department stated.
The video sparked thousands of reactions, including from Mr Trump, who responded: “Animals that must be hit hard!”
To the protesters blocking the entrance & exit of the HOSPITAL EMERGENCY ROOM yelling "We hope they die" referring to 2 LA Sheriff's ambushed today in #Compton: DO NOT BLOCK EMERGENCY ENTRIES & EXITS TO THE HOSPITAL. People's lives are at stake when ambulances can't get through.
Advertisement— LA County Sheriffs (@LASDHQ) September 13, 2020
Protesters gathered outside the emergency room at the hospital where the injured deputies were being treated.
“To the protesters blocking the entrance & exit of the hospital emergency room yelling ‘We hope they die’ referring to 2 LA Sheriff’s ambushed today in #Compton: Do not block emergency entries and exits to the hospital,” the sheriff’s department tweeted.
“People’s lives are at stake when ambulances can’t get through.”
Moments ago, 2 of our Sheriff Deputies were shot in Compton and were transported to a local hospital. They are both still fighting for their lives, so please keep them in your thoughts and prayers. We will update this thread with information as it becomes available.
— LA County Sheriffs (@LASDHQ) September 13, 2020
A radio reporter who was near the protest scene was taken into custody, KABC-TV reported.
It was not immediately clear why she was detained.
Captain Kent Wegener said officers were blanketing the area in search of a suspect seen on the video opening fire with a pistol.
“We have a very, very generic description,” he said.
The incident happened around 7pm, a short distance from the Compton sheriff’s station.