Mattis gave a blunt warning against generals becoming politicians, and in neighboring country where this is happening

Defense Secretary Jim Mattis during a visit to the Monument to the Dead of World War II in Rio de Janeiro, August 14, 2018. REUTERS/Sergio Moraes

During a trip to Brazil, Defense Secretary Jim Mattis emphasized that military officers should avoid politicization.

His words of caution applies to the US, where retired military officers have run for office or taken part in campaigns.

But they likely carry more weight in Brazil, where support for a military role in government is growing.

On the first stop on a four-country Latin American tour, Defense Secretary Jim Mattis this week argued for closer defense ties between the US 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 US.

Mattis, a revered leader who served in the US 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."

Mattis with President Donald Trump at the White House. Chris Kleponis-Pool/Getty Images

But he emphasized that the US 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.'"

Former military officers getting involved in US 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.

Trump with Michael Flynn at a campaign event. George Frey/Getty Images

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.

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.

Brazilian congressman Jair Bolsonaro with soldiers and cadets at an Army Day ceremony, in Brasilia, April 19, 2017. (AP Photo/Eraldo Peres)

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 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."

Members of Brazil's military frisk residents during an operation against drug dealers in the Cidade de Deus slum in Rio de Janeiro, February 7, 2018. REUTERS/Ricardo Moraes

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."