The attack took place late yesterday as the seven vehicles carrying paramilitary gendarmerie officers were on patrol in Ocotlan, Jalisco state, the federal police said in a statement.
Eight other officers were wounded, including one in serious condition.
It was the deadliest shooting for Mexico's new gendarmerie, a 5,000-strong unit modelled after European military-like forces that President Enrique Pena Nieto launched last year to protect key economic sectors from organised crime.
"We have regrettably had minor losses of one officer in some other events," but never so many in one attack, a federal official told AFP.
Also Read
The police statement said the officers were on patrol at around 9:15 pm when a vehicle approached the convoy and "without uttering a word, one of the individuals pulled out a large weapon and shot at the federal agents."
The officers shot back and more gunmen arrived in about 10 other vehicles, firing in all directions.
The gendarmerie commander said the shootout lasted 30 minutes and took place in several streets.
"As a result of this clash, we report the deaths of five gendarmerie division officers and three civilians whose bodies had cartridge belts and tactical equipment and who presumably are part of organised crime," the statement said.
The statement did not say what criminal organisation the suspects belong to, but the region is home to the Jalisco New Generation drug cartel.
The suspects kept shooting as they fled the scene, leaving bullet holes in several vehicles parked in several neighbouring streets.
Authorities found seven "large weapons" -- a term usually referring to assault rifles -- and four grenades. The suspects left behind five vehicles.
The federal attorney general's office will investigate the attack.