KABUL, Afghanistan — The two main contenders in Afghanistan’s presidential election both claimed they were ahead on Monday after ballot counting had barely begun, raising fears of a new political crisis in a nation convulsed by protracted war.

The contradictory claims by the camps of President Ashraf Ghani and his opponent, Abdullah Abdullah, came two days after the voting was held despite hundreds of attacks by Taliban insurgents, who had called the election illegitimate and warned Afghans not to participate.

Afghanistan’s election commission, the body administering the vote and responsible for declaring its winners, was feeling the weight of the task even before the camps of Mr. Ghani and Mr. Abdullah asserted they were winning.

The voting on Saturday was so far regarded as relatively clean compared with previous elections that were marred by widespread fraud.