Police officers on an operation tackling gun crime were shot at while inside an unmarked car.
Five men have been arrested on suspicion of attempted murder after the officers were targeted in Ladywood, Birmingham.
Nobody was injured, West Midlands Police said.
The police car was shot at just after midnight on Tuesday near Crosby Close and St Marks Crescent, the street where a teenager was shot dead last year.
A car believed to be involved was found in West Bromwich, the force added.
ACC Sarah Boycott from West Midlands Police said armed officers were patrolling the streets of Ladywood to reassure residents.
"Officers were working on a proactive operation to tackle gun crime and keep people safe and it is unusual that they should come under attack in this way in the line of that duty," she said.
"There is a minority within our society who don't give a second thought to illegally carrying and using guns and although these are significant arrests we will continue to take action against those who think it's OK to carry guns on our streets."