The first openly gay mayor in Mexico, who made history when he was elected in July, has been sworn in at a ceremony in Fresnillo, Zacatecas – a city known for its anti-gay conservative values and drug-related warfare.

Benjamin Medrano, a 47-year-old singer and owner of a gay bar, has now taken office as mayor despite anti-gay “smear” campaigns targeted against him.

He said he was previously the target of an anti-gay phone-calling campaign in which his political rivals “tried to smear me, as if being gay were a crime.”

He acknowledged Zacatecas is a largely rural and conservative state, and said it was one of the last places in Mexico that someone would expect to see a gay mayor.

He added: “Somewhat? Very machisto, I would say. I am going to be mayor of a township where there are 258 villages full of tough country people, who don’t necessarily have much information on what’s happening elsewhere, and have even less of an automatic sympathy with their gay mayor.”

While some top Mexican legislators and mayors have been rumored to be gay, none have ever previously been open about their sexuality.

Alejandro Brito, director of the gay rights group Letra S, said: “He is the first. There have been city officials and city council members, but openly gay mayors? No.”

Mr Brito added: “This shows that our human rights system is providing some protection. Because, even though there is no public majority in favor of electing gay politicians, he knows that the legal framework will protect him.

“It is now more risky for a political rival to be openly homophobic, than it is to be a homosexual candidate.”

Fresnillo, the second largest city in Zacatecas state, north central Mexico, is known for its problems with drug cartels.

Mr Medrano campaigned on a strong public-safety platform, advocating cooperation with state and federal police, and vetting and background checks on the notoriously corrupt local police force.

Bodies have been found hacked to bits, others with their throats slit, some decapitated, some stuffed in wells or shallow graves.

Mr Medrano said he was “not at risk,” however, as he had no “relationship” with either of the two drug cartels. He said he hoped to make a difference for the people in the city.

He posted a message on his Twitter account soon after the ceremony: “I’m sure #Fresnillo is eager for a change and we will achieve together of all who live here!”

Two of Mexico’s biggest criminal organisations – Los Zetas and the Gulf Cartel – have been fighting for control of drug trafficking routes leading north towards the American border.

Mr Medrano said: “What matters the least for the people is who you may sleep with, what you do in your private life. What they want is good results from their politicians.”

On the issue of same-sex marriage and gay equality, Mr Medrano previously noted: “It’s not like I’m going to paint city hall pink, either.”

The mayor, who is a Roman Catholic, said he was “not in favour of gay marriage” when he was elected in July.

He said: “I wish the church had a different view, but I cannot go against doctrine. I respect my church, and I don’t want to dig any deeper beyond what’s permitted and what is appropriate.”

In a recent interview with BBC Mundo, however, he said that although he has no plans to marry himself, he is no longer strictly against same-sex marriage.

He added: “My agenda is based on achieving human and social development for all of us who live in Fresnillo, regardless of sexual orientation.”

Being gay has been legal in Mexico since the 19th century, and there are a number of laws banning anti-gay discrimination.

However, 95 per cent of Mexican LGBTs still feel oppressed by others, according to recent surveys, as the strong Catholic influence on society means many people regard homosexuality as immoral.