European Union leaders, faced with a staggering migration crisis and deep divisions over how to tackle it, have agreed to boost border controls and send one billion euros (£733 million) to international agencies helping refugees camped near their countries.
The leaders also said task forces of European experts sent to help register and screen migrants in so-called hotspots must be fully operational in Greece and Italy, and perhaps also Bulgaria, by November.
The move is intended to quickly identify migrants eligible for refugee status and relocation into other European countries, and to filter out economic migrants who are unlikely to qualify for asylum in Europe.
"The measures we have agreed today will not end the crisis. But they are all necessary steps in the right direction," EU Council president Donald Tusk said at the conclusion of the meeting, which laster more than seven hours.
He added that European leaders, who have disagreed acrimoniously with one another over how best to tackle the flow of people into the continent, finally appeared to reach agreement.
"Tonight we have a common understanding that we cannot continue like we did before," he said, adding that the crisis would only deepen.
"It is clear that the greatest tide of refugees and migrants is yet to come," he said. "Therefore we need to correct the policy of open doors and windows."
The leaders also pledged to boost support to Lebanon, Turkey and Jordan to help them cope with the millions fleeing the fighting in Syria.
"The more money we give to address the root causes that are driving people to leave, the less likely they will be to leave their homes," German chancellor Angela Merkel said.
Around half a million people have fled to Europe so far this year in search of sanctuary or jobs. As numbers swell, nations have tightened border security. Hungary has put up a razor-wire fence along its border with Serbia and is close to completing a similar fence separating it from fellow EU member Croatia.
Many of the migrants are arriving via risky boat crossings from Turkey to the Greek islands.
Hungary's hardline prime minister Viktor Orban, who has faced fierce criticism for his border fences, said he got much of what he wanted from the meeting, but added that leaders did not go far enough in bolstering border protection.
"In this sense, Europe's external border is still not defended and the migrants breaking international agreements continue to come through Greece," he said. "This is the situation now and we could not put a stop to it."
British prime minister David Cameron said his country would donate £100 million - including £40 million to the World Food Programme - to help feed refugees in camps close to the conflicts they are fleeing.
"We must make sure that people in refugee camps are properly fed and looked after, not least to help them but also to stop people wanting to make, or thinking of making this very, very difficult and very dangerous journey to Europe," he said.
As the session began on Wednesday evening, Mr Tusk urged divided EU nations to set aside their differences and work together to hammer out a concrete plan "in place of the arguments and the chaos we have witnessed in the last weeks".
But French president Francois Hollande was more blunt.
"Those who don't share our values, those who don't even want to respect those principles, need to start asking themselves questions about their place in the European Union," he said on his way into the meeting.
His remarks came after four eastern European nations - the Czech Republic, Slovakia, Hungary and Romania - voted against a plan adopted on Tuesday to relocate 120,000 asylum seekers to other member states over the next two years to ease the strain on Italy and Greece, which are on the front line of the crisis. European officials said the vote was binding on all countries, including those that voted against it.
Slovakia's prime minister Robert Fico, however, has vowed to go to court to fight the plan.