RIO DE JANEIRO — The United States and Brazil have been uneasy allies during the best of times.

But Brazilian voters may have put an end to that dynamic by electing as their next president Jair Bolsonaro, a far-right lawmaker who is unabashedly pro-American and strikingly similar to President Trump in temperament, tactics and style.

“We might be on the verge of a golden era of relations,” said Fernando Cutz, a former senior White House official who worked on Latin America policy in the Obama and Trump administrations. “Trump and Bolsonaro will really hit it off. Their personalities are almost identical and their policy views are very similar.”

Mr. Bolsonaro’s enthusiasm for closer ties with the United States is among the starkest signs that Brazil’s foreign policy is about to undergo profound changes.

As a candidate, the incoming president denounced the alliances and foreign policy of the leftist Workers’ Party, which governed Brazil from 2003 to 2016. During that period, Brazil fostered close commercial ties with China, championed Cuba’s authoritarian government and was a pillar of multilateral alliances that excluded the United States.