TEHRAN — Iran’s presidential race entered a new, unpredictable phase on Saturday when two game-changing politicians, both out of favor with the country’s leaders, signed up as candidates in the final minutes of a five-day registration period.

Esfandiar Rahim Mashaei, a protégé of President Mahmoud Ahmadinejad, and former President Ali Akbar Hashemi Rafsanjani, who was soundly defeated by Mr. Ahmadinejad in the 2005 election, arrived simultaneously at the Interior Ministry headquarters in the capital, Tehran, to register. The building was cordoned off by security forces restraining hundreds of people, who were shouting slogans in favor of and against Mr. Mashaei.

Both men had kept analysts wondering until the last minute whether they would participate in the elections, set for June 14. If their candidacies are approved by a council of conservative clerics and jurists — a hurdle that analysts say will not be easy — the men are virtually certain to shake up the campaign because they hold views that challenge Iran’s governing establishment, a loose alliance of conservative Shiite Muslim clerics and Revolutionary Guards commanders who hold sway over the country’s judiciary, security forces, Parliament and state news media.

The men’s criticisms of those governing behind the scenes will undoubtedly appeal to Iran’s dissatisfied urban voters. But they also strongly oppose each other, setting the stage for a highly contested election if both men win approval to run.