The choice was between former Foreign Minister Abdullah Abdullah and ex-World Bank economist Ashraf Ghani.
The head of the election commission said turnout was good and most polling stations had opened but admitted some places had run out of ballot papers.
The Taliban threatened to target voting, and there are concerns that fraud could produce a disputed result.
It should be the first time that power in Afghanistan has been democratically transferred.
As most foreign soldiers prepare to withdraw by the end of this year, whoever becomes the new leader faces multiple challenges.
Taliban insurgents remain active, the economy is weak, corruption is endemic and the rule of law goes largely unenforced.
About 12 million Afghans are eligible to vote. Polls closed at 16:00 local time but officials said those in line at that time could still vote.
The election commission said 6,204 polling centres had opened, but about 160 remained closed because of security threats.
Abdullah Abdullah won 45% of the first-round vote, with Ashraf Ghani securing 31.6% – neither achieved the 50% needed to avoid a second round.
Both sides have faced multiple claims of fraud.
Correspondents say that a seamless transfer of power would be a significant achievement for Afghanistan and a vindication of international efforts to establish a functioning democracy after the abuses of the Taliban era.
But Afghanistan’s mountainous and remote terrain, coupled with the dilapidated condition of many of its roads, mean that holding a country-wide election is a major challenge. Thousands of donkeys will be deployed to carry ballot boxes to some of the more inaccessible villages.
The preliminary result is expected on July 2 and the final result on July 22.
XWhMJM58NDMThe US House Ethics Committee has voted to release its report on former Republican Representative…
ABC News has agreed to pay $15 million to President-elect Donald Trump to settle a…
South Korea’s parliament has voted to impeach President Yoon Suk Yeol over his failed attempt…
Israeli war planes have carried out more than 100 air strikes in Syria on December…
President-elect Donald Trump has threatened to impose 100% tariffs on the BRICS countries if they…
Syrian troops have withdrawn from the city of Aleppo following an offensive by rebels opposed…