MEXICO CITY — Guatemalan legislators on Monday overwhelmingly voted to keep President Jimmy Morales’s immunity from prosecution, a measure that protects him from a campaign finance investigation that has roiled the country’s politics.

The vote in Congress rejected a request from Guatemala’s attorney general and the head of a United Nations anticorruption panel, which last month described a series of violations by Mr. Morales’s party and two other parties during the 2015 election campaign.

With so many legislators embroiled in questions over campaign finance, the congressional vote not to remove the president’s immunity appeared to be a decision to close ranks against the investigation.

“It was a predictable decision,” said Alejandro Rodríguez, director of justice programs for Impunity Watch, a human rights organization. “Corrupt politicians are trying to prevent the country from changing.”