EU states on Wednesday agreed to the final part of an overhaul for rules on how they handle asylum seekers and irregular migrants, setting up a push to make it law by elections next year.

Ambassadors from the 27 countries struck the deal in Brussels after Italy and Germany ironed out a last-minute row over charities rescuing migrants stranded in the Mediterranean.

German Chancellor Olaf Scholz called the migration system overhaul "a historic turning point".

"The reform will be effective in limiting irregular migration in Europe and provide lasting relief to countries like Germany," he wrote.

The goal of the EU is to have the long-stalled changes made law before European elections next June that will usher in a new European parliament and commission.

"We are now in a better position to reach an agreement on the entire asylum and migration pact with the European Parliament by the end of this semester," Spain's interior minister Fernando Grande-Marlaska, whose country holds the EU's rotating presidency, said.

European Commission vice-president Margaritis Schinas called the text the "last missing link of the package" and urged EU states and parliament to now forge ahead with the protracted negotiations to make it law.

"We need the pact done and dusted before Europeans go out to vote," Schinas said.

The next cycle in EU politics could see a political shift in the parliament, given the rise of right-wing parties in several EU countries, and would see Hungary and Poland take turns holding the rotating EU presidency.

Once implemented, the new Pact on Migration and Asylum would seek to relieve the pressure on so-called frontline countries such as Italy and Greece by relocating some arrivals to other EU states.

Those countries opposed to hosting asylum-seekers -- Poland and Hungary among them -- would be required to pay the ones that do take migrants in.

At the same time, the European Union will seek to speed up processing of asylum applications so that migrants deemed inadmissible are returned to their country of origin or of transit, and maximum detention times for migrants in border centres would be lengthened from the current 12 weeks.

- Hungary, Poland opposed -

Paralysis on the issue had caused growing frustration in the bloc as it faces a rise in irregular migration.

The recent arrival of thousands of asylum-seekers arriving from Africa on the Italian island of Lampedusa notably spurred urgency to get the revised policy in place.

Part of the aim of the revised policy is for EU countries to act together should they be faced with a sudden large inflow of asylum seekers, as happened in 2015-2016 when hundreds of thousands of migrants arrived, most of them Syrians fleeing the war in their country.

Agreement among EU member states only needed a weighted majority of countries, meaning opposition from Poland and Hungary did not derail the agreement.

Warsaw and Budapest have been outspoken in their criticism of the push to get them to accept or pay up for migrants.

Poland's right-wing governing party has made immigration a major part of fiercely contested elections this month and has staged a referendum on the issue for the same day.

Hungary's Foreign Minister Peter Szijjarto fired off another broadside against the reforms on Wednesday.

"We call on Brussels to end this migration policy immediately," he said.

The rancour over migration is set to figure prominently at two days of summits involving EU leaders in Spanish city Granada starting Thursday.