ISTANBUL — Heavy voter turnout in Iran brought huge lines and extended voting hours Friday in a pivotal presidential election that could either boost Iran’s engagement with the world or possibly plunge the country back into greater diplomatic isolation.

Across the nation, voters filed into schools, mosques and other sites to cast ballots after a campaign offering starkly differing visions.

In the balance was Iran’s international outreach – as well as its national identity as a state either moving toward more social and political openness or turning inward to assuage Iranians troubled by reforms and economic stagnation.

Also at stake was the legacy of the incumbent president, Hassan Rouhani, who ended more than a decade of U.N. sanctions as part of a 2015 nuclear deal with world powers.