The exhausted heads of state and government burst into applause as the deal was struck at 0430 local time (0330 GMT) after an 18-hour session.
The agreement came after hours of wrangling over how much say each member state should have in decision-making.
BBC Europe Correspondent Angus Roxburgh says this is not the radical treaty that was originally envisaged, and will not necessarily make the EU less cumbersome.
The big countries, as expected, gained influence in the Council of Ministers, the main decision-making body in the European Union.
President Chirac of France said the five-day summit would go down in history for its complexity and as a great success.
The British Prime Minister, Tony Blair, said it had been a very difficult and complicated negotiation.
"This is a big day for Europe", said Swedish Prime Minister Goran Persson. "We are ready for enlargement."
Rebellion
The plans for the EU's bigger countries to have greater voting power had provoked a rebellion by the small states and successive concessions had to be made until Portugal and finally Belgium fell into line.
The Portuguese Prime Minister, Antonio Guterres, who had been the most critical, said after the deal that it had deepened the union and created a better Europe for enlargement.
Smaller countries had been concerned that their power would diminish as the EU expands to include countries from Central and Eastern Europe.
Belgium Prime Minister Guy Verhofstadt was arguing that it was unfair to expect Belgium to accept one less vote than the Netherlands, on the grounds that the latter had 50% more people, while Germany had the same number of votes as France, despite having 40% more population.
But Belgium finally agreed to accept the new voting plan, without any further concessions.
Midnight hour
France, Germany, Italy and the United Kingdom will each have 29 votes - one vote less than originally planned - while several smaller countries have gained an extra vote from the original draft.
The French plan called for a double majority for decision-making in the EU's Council of Ministers - one based on individual votes, and a second calculated according to national populations.
New voting allocation
France, Germany, Italy, UK : 29
Spain: 27
Netherlands: 13
Belgium, Greece, Portugal: 12
Sweden, Austria: 10
Denmark, Finland, Ireland: 7
Luxembourg: 4
For a motion to pass, once the EU has enlarged to 27 states, it must gain 255 votes out of a total of 345. There is also an additional "demographic net" which demands that the countries backing it must represent at least 62% of the EU's population.
The reforms are considered to be crucial as the 15-nation bloc prepares for enlargement, with a dozen countries expected to join over the next decade.
Majority voting
EU leaders managed to reach an "agreement in principle" on a shorter list of policy areas subject to national vetoes at EU ministerial meetings.
Qualified Majority Voting hurdles
Now:
62 votes out of 87
Post-enlargement:
255 votes out of 345
Half of member states
62% of EU population
There is now an end to national vetoes on international trade although France managed to get an exception for film industry while Denmark and Greece insisted on some clauses relating to transport.
The general framework has been put in place for justice and internal affairs but on asylum and immigration, Germany won the right to maintain a veto until 2004
Regional aid will be sorted out under the qualified majority voting system (QMV) from 2007.
Industrial policy, which is seen as uncontentious, moves to QMV while the UK won a victory that means taxation and social security will stay under its control.
Although no firm target date was set for expansion, and countries can only join after meeting tough EU economic and political terms, the EU leaders said they hoped to open the doors before the June 2004 European Parliament elections.
All applicants have introduced painful economic reforms to qualify to join the EU but still face tough negotiations on sensitive issues like farming and the free movement of workers.
EU officials say that while the Nice accord removed some of the uncertainty for candidates, the difficulties leaders had in overhauling the EU's creaking structures showed how complicated expansion will be.