Three years after the country's revolution, the law was passed by 132 votes in favour, 11 against and nine abstentions in the 217-member National Constituent Assembly.
The assembly, which started voting on the law article by article last Friday, had initially set itself an April 27 target to wind up the often rowdy debate.
A major bone of contention that led to insults being traded was over a proposed ban on officials of the ousted regime from standing for office, a proposal which was rejected by a single vote.
The planned elections aim to create permanent institutions in the country that in 2011 spawned the Arab Spring but which remains plagued by prolonged political crises, social conflict and a rise of jihadist groups.
More From This Section
The body responsible for organising the elections still has no budget, no office and no legislation on which to base its work.
It has said it would need between six and eight months to organise elections once the law was passed.
The constitution allows for a dual executive system, with the prime minister exercising the pivotal role but accountable to parliament.