On the first stop on a four-country Latin American tour, Defense Secretary Jim Mattis this week argued for closer defense ties between the U.S. and Brazil, the region's biggest economy.

Speaking at Brazil's war college, Mattis stressed the need of regional cooperation and political solutions, especially on issues like the crisis in Venezuela, but when asked about the role of the military in politics, a question of increasing interest to Brazilians, he gave an answer that applies to both Brazil and the U.S.

Mattis, a revered leader who served in the U.S. Marine Corps for 44 years and rose to the rank of general, stressed that he had no role in the Trump campaign and described serving in government as a matter of duty.

“We come from the military, and we have kind of a saying in America, if the president of the United States asks you to do something, whether you're on active duty or retired, you don't go up like Hamlet and start wringing your hands,” Mattis said. “Republican or Democrat, the answer is 'yes, sir,' or 'yes, ma'am.' There is no equivocation.”

But he emphasized that the U.S. military is and should remain under civilian control and warned against military officers taking a role in politics.

“I think that it is wrong in America … as a retired general or admiral, to come out in a public position supporting one candidate or another,” Mattis added. “The reason is we do not want to politicize the officer corps, and I don't want anyone thinking when they have a general in the room, 'Well, he retires next year. I wonder what he's going to do after that.'”

Mattis Delivered A Warning About Politicizing The Military Amid Brazil’s Election Turmoil

James Mattis, U.S. Secretary of Defense, and received with military hours and reviewed the troops in the defense ministry before meeting with Joaquim Silva e Luna, Minister of DefenseAssociated Press/Mateus Bonomi

Former military officers getting involved in U.S. politics isn't new.

Dwight Eisenhower retired from the Army as a general in 1952 and became president in January 1953, serving two terms as a Republican. Wesley Clark, who retired as an Army general in 2000, ran for president as a Democrat in 2004.

Others former generals have been vocal supporters of campaigns.

Michael Flynn, who retired as an Army general in 2014, was an active supporter of Donald Trump during the 2016 presidential campaign and briefly served as national security adviser. (Flynn pleaded guilty to lying to the FBI in late 2017, and a number of the military officers who backed Trump had blemishes on their records.)

John Allen, a retired Marine general, gave a speech for Hillary Clinton at the 2016 Democratic National Convention, though some attendees were not pleased with his presence.

Related: A Little Humility On The Part Of The Military Might Help Bridge The Civil-Military Divide »

Mattis' comments are likely to resonate more sharply in Brazil, which will vote for a new president in October.

There are a number of candidates, but one of the frontrunners, Jair Bolsonaro — a former army captain who has compared himself to President Donald Trump — has spoken approvingly of the military dictatorship that ruled the country from 1964 to 1985 and promised a more prominent role for the military in his government.

That sentiment has been growing in Brazil, where rising crime, rampant corruption, and economic struggles have disillusioned many. A number of military officers are already running for office this year, and Bolsonaro has said he would put generals in charge of ministries — “not because they are generals, but because they are competent.”

This month, Bolsonaro picked retired army Gen. Antonio Hamilton Mourao as his running mate. Mourao made waves last year with remarks seen as supportive of military intervention to address social problems. (The military has already been deployed in Brazil to fight crime.) After being picked, Mourao said it was “an honor and privilege to take part in the country's reconstruction.”

The pick was seen as a move by Bolsonaro to solidify his image as the law-and-order candidate. “And we're going to have many ministers from the military as well, make no mistake,” Bolsonaro said.

Bolsonaro said his picks would depend on ability, and while he admitted generals were not incorruptible, he said with them, malfeasance would be less common. “I believe it's difficult to make a military person corrupt.”

Mattis Delivered A Warning About Politicizing The Military Amid Brazil’s Election Turmoil

Brazilian congressman Jair Bolsonaro poses for photos with soldiers and cadets during a a ceremony commemorating Army Day, in Brasilia, Brazil, Wednesday, April 19, 2017. Bolsonaro, a potential presidential candidate for Brazil's 2018 election, is backed by the military and some conservative sectors.Associated Press/Eraldo Peres

A Bolsonaro victory is not assured. Polls still show him in second place, behind former President Luiz Ignacio “Lula” da Silva, who is in jail on a corruption conviction and may not be eligible for office. The two-round format of the election also means another candidate could triumph.

But his elevation of the military worries many in a country where memories of the dictatorship's abuses endure. The current widespread use of the military for domestic security has already led to abuses.

Mattis — who needed a Congressional waiver to be defense secretary because he hadn't been out of uniform long enough — drew a distinction for military officers between being a government official and becoming a politician.

“I don't think there's any problem with serving,” Mattis said at the war college. “We just have to be very careful that we don't participate … election campaigns, where we feel, whether on active-duty or retired status, that our guy or gal won or lost.”

“So I'm not in any way against them serving,” he added. “I would be very much against them taking a political role in a campaign.”

Read more from Business Insider: