Two suspects are in custody, one of whom was shot and is receiving medical treatment, officials said.
Police identified the officer who was fatally shot as Sgt. Wytasha Carter, 44, who had been with the department since 2011. They haven't released the names of the wounded officer or the suspects.
Birmingham Police Chief Patrick Smith said the officers approached the two suspects just before 2 a.m. outside a nightclub in downtown Birmingham, after a plainclothes officer spotted one checking door handles on cars parked outside the venue. Smith said one suspect opened fire after being confronted by the officers.
RELATED: Officer expected to be okay following shooting during traffic stop
"This is one of the roughest hours of your career," Smith said at a news conference, according to local media reports. "There's not a chief, not an officer that ever wants to have to deal with this. This is a very difficult thing for the family, very difficult for the department."
Officers were working a special detail in response to a rash of car break-ins in that area. When the undercover officer spotted suspects who appeared to be testing door handles on cars, he called for backup and Carter arrived, officials said.
"The officers approached one suspect and patted him down where they found what they believed to be a weapon," Smith said. "They asked him about it, he armed himself and fired upon our officers."
Smith added: "It appears our officers were unable to respond. They were taken completely by surprise. We can't go into great detail because we are still in the infancy stage of the investigation."
RELATED: Two female rookie police officers shot and killed in two days
Carter began his law enforcement career in 2002 as a correctional officer with the Shelby County Sheriff's Office and worked for two other police departments before transferring to the Birmingham department. He was promoted to sergeant in February 2018.
News outlets said this is the first Birmingham officer killed in the line of duty in more than 14 years.
Birmingham Mayor Randall Woodfin called for prayers on Twitter.
"Join me in praying for the family of the Birmingham Police officer killed early this morning, and the officer who is currently in the hospital. They were shot while serving and protecting our city," he tweeted.
U.S. Attorney Jay E. Town issued a statement calling the shooting "a heartbreaking reminder of the dangers all law enforcement face while we sleep."