Nearly three years ago, there was electricity in the air when Andrés Manuel López Obrador stepped up to the microphone in Mexico City’s main square to address a crowd.

He had just channelled deep disgust over corruption into a landslide election victory and in a message designed to appease those who feared he was a dangerous populist, the new president promised to deliver “profound change, but in accordance with the established legal order”.

As the halfway point in his term approaches, he still wants to transform Mexico. But his vow to respect the law appears increasingly tenuous.

In the space of a week at the end of April, he caused controversy by endorsing a two-year extension to the Supreme Court president’s term despite questions over the constitutionality of the move. He then pledged to scrap autonomous institutions whose rulings he disagrees with and accused opponents of “conspiring against democracy”.

He says he is upholding the will of the people — something he insists past governments failed to do.

“Mr López Obrador believes the popular mandate he won in the elections is sufficient for his projects to pass . . . that it gives him permission to violate the constitution or break laws,” said Ana Laura Magaloni, a constitutional expert.

However, polls show Mexicans are also dissatisfied with the economy, crime and his handling of the coronavirus pandemic.

The president says he respects the constitution but justice comes first. As he put it two years ago: “The constitution establishes that there must be justice. Justice is above everything. If you had to choose between the law and justice, don’t think too hard, pick justice.”

In supporting an extension of the Supreme Court president’s mandate, many believe López Obrador has crossed a line and is compromising the respected institution’s integrity.

Others see it as a way of eliminating potential opposition to his reform agenda: the president needs court approval to continue his efforts to undo landmark 2013 energy reforms that he sees as a key part of his drive to rebuild a strong state apparatus, eradicate corruption and put the poor first.

The constitution bans presidential re-election and with the pandemic complicating his progress, Alejandra Cullen, a political analyst, saw the Supreme Court move as a way of López Obrador “sounding out” the prospect of extending his own term, despite his regular insistence that he would leave office in 2024. “You can’t read it any other way,” she said.

“I think he wants to have as few checks and balances as possible,” she added.

Indeed, within days last week, López Obrador lashed out at an electoral court ruling preventing two candidates from his Morena party from running in gubernatorial elections on June 6.

He said the sanction was out of proportion with the men’s failure to clarify pre-campaign spending amounting to $950 in one case, and $700 in the other, and was a denial of their right to run for office — something on which he said the people should have the last word.

“This is an attack on Mexico’s incipient democracy,” he said. “Democracy is respect for the will of the people.”

López Obrador has since stepped up his attacks on other institutions, such as the competition watchdog and transparency institute, calling them a “monster” that needs getting rid of.

Luis Estrada at Spin, a consultancy, said it was part of an intensifying campaign to discredit them in the run-up to the important midterm vote in June, in which the president is widely expected to cry foul if his candidates do not win.

All 500 seats in the lower house of Congress, where López Obrador has a majority, are up for election, as well as 15 governorships.

Although polls put Morena comfortably ahead, opposition parties have teamed up in parts of the country and have mounted credible challenges to the party in some areas, setting the stage for a tense race.

“The post-election conflict has already started,” Estrada said.