RIO DE JANEIRO — Members of Brazil’s armed forces, who have largely stayed out of political life since the end of the military dictatorship 30 years ago, are making their biggest incursion into politics in decades, with some even warning of a military intervention.

Retired generals and other former officers with strong ties to the military leadership are mounting a sweeping election campaign, backing about 90 military veterans running for an array of posts — including the presidency — in national elections this October. The effort is necessary, they argue, to rescue the nation from an entrenched leadership that has mismanaged the economy, failed to curb soaring violence and brazenly stolen billions of dollars through corruption.

And if the ballot box does not bring change quickly enough, some prominent former generals warn that military leaders may feel compelled to step in and reboot the political system by force.

“We are in a critical moment, walking right up to the razor’s edge,” said Antonio Mourão, a four-star general who recently retired after suggesting last year, while in uniform, that a military intervention might be necessary to purge the corrupt ruling class. “We still believe that the electoral process will represent a preliminary solution for us to shift course.”