European Union leaders have reached a deal on a landmark treaty to reform the 27-member bloc, officials say.
The treaty will be formally signed by European leaders in mid-December
The agreement in Lisbon was sealed shortly after midnight after objections from Italy and Poland were overcome.
The treaty is designed to replace the European Constitution that was rejected by French and Dutch voters in 2005 and will be formally signed on 13 December.
It includes the creation of a new longer-term president of the European Council and an EU foreign policy chief.
If what will become known as the Treaty of Lisbon is ratified by all member states, it will come into force in 2009.
After seven hours of talks, EU leaders emerged embracing and slapping each other on the back in sheer relief that the most serious crisis in the bloc's 50-year history seemed to be over, the BBC's Oana Lungescu in Lisbon says.
In the last-minute negotiations, Italy gained an extra seat in the future European Parliament, returning it to parity with the UK and restoring Italian national pride, our correspondent says.
Poland secured a guarantee that small groups of countries would be able to delay EU decisions they do not like - a victory for the Polish government just days before Sunday's early parliamentary election, she adds.
Earlier, Austria reached a deal over its bid to maintain quotas for foreign students, with the European Commission agreeing to suspend for five years its legal action over the country's quota.
Bulgaria also won the right to call the EU single currency the "evro", rather than euro, in its Cyrillic alphabet.
The new Reform Treaty is designed to speed up decision making in the expanded European Union. It will also create a new president of the European Council, a new EU foreign affairs chief, a reformed voting system and scrap vetoes in dozens of areas.
However, the 250-page document has been stripped of any trappings of a super-state, such as the mention of the EU anthem and flag.
It amends, rather than replaces, existing EU treaties, a point which some countries - notably the UK - have argued means there is no need for national referendums on the document.
After the agreement was reached, Jose Socrates, the prime minister of Portugal, which holds the rotating presidency, said Europe had emerged from an "institutional crisis".
The UK government says the treaty respects Britain's "red lines"
"With this treaty, Europe is showing that the European project is on the move. Now we can look forward to the future with confidence," he added.
European Commission President Jose Manuel Barroso said the treaty was a "great achievement".
"I believe we have a treaty that will give us now the capacity to act," he said.
"Our citizens want results. They want to see in concrete terms what Europe brings them in their daily lives."
The UK government had little to say in Friday's negotiations.
Prime Minister Gordon Brown said the UK's "red lines", which his government had declared around various policy areas, had been secured.
"The British national interest has been protected," he added.
On Thursday, Mr Brown once again ruled out a referendum on the treaty.
Despite pressure in the UK and several other countries for a popular vote, only Ireland is legally bound to hold a referendum, and most governments will do what they can to avoid another embarrassing failure, our correspondent Oana Lungescu says.