This article is more than
2 year oldPolice say gunmen stormed the San Miguel Totolapan town hall at 14:00 (19:00 GMT) on Wednesday. Photos online show it riddled with bullet holes.
Mayor Conrado Mendoza Almeda's left-wing PRD party condemned his "cowardly" assassination and demanded justice.
The attack has been blamed on the Los Tequileros criminal gang, which is linked to a powerful drug cartel.
Police officers and council workers were also killed in the massacre, with graphic images of bloodied bodies lying on the ground circulating on social media.
Mr Mendoza Almeda's father, former mayor Juan Mendoza Acosta, was also killed - in his home - before the attack moved to the town hall.
A highway in the state of Guerrero, where San Miguel Totolapan lies, was reportedly briefly blocked by large vehicles to prevent security forces from getting into the city.
Even by the violent standards of Guerrero state, this was a shocking attack, reports the BBC's Mexico correspondent, Will Grant.
San Miguel Totolapan lies in the heart of a region known as Tierra Caliente, a violent part of drug cartel-controlled western Mexico.
Various groups battle for control of the lucrative drug routes north along the Pacific corridor, our correspondent adds. The region is a hotspot for the growing of opium poppies and the production of heroin.
In a preliminary report seen by local media, Guerrero's attorney general said that as well as the 18 people who were killed, three others were wounded.
It is not yet clear what the motive behind the attack may have been but killings of local officials are not uncommon.
In 2018, at least three dozen mayors, former mayors and mayoral candidates were killed. The number has dwindled to single figures in recent years but those who hold local office remain at risk from armed gangs, which often want to be the only authority in town.
Following the attack, the defence ministry said it was deploying army and navy units to the area to find the gunmen.
Guerrero Governor Evelyn Salgado Pineda tweeted to say she deeply regretted the deaths.
Shortly before the attack, alleged members of Los Tequileros released a video on social networks announcing its return to the region, where they had been fighting a rival drug gang.
The criminal group devastated Guerrero between 2015 and 2017 - and was known for threatening mayors of the region - until its leader Raybel Jacobo de Almonte was assassinated.
De Almonte was known as El Tequilero - the Tequila Drinker - and his gang took their name from him.
Additional reporting by Tiffany Wertheimer
Newer articles
<p>A US judge has ruled against Donald Trump getting his hush money conviction thrown out on immunity grounds.</p>