They agreed to start relocating a little over 32,000 of the arrivals among the EU's 28 members in October, falling around 8,000 short of the target agreed by EU leaders at a summit in June.
"We are almost there. The remaining 8,000 will be allocated by the end of this year, by December," EU home affairs commissioner Dimitris Avramopoulos told a press conference.
"I'm disappointed this did not happen today, but it was a very important step forward," he added.
The European Commission originally proposed the 40,000 figure after an unprecedented migrant shipwreck in the Mediterranean in April that left nearly 800 people dead.
EU leaders agreed on the figure in June but have been bitterly divided over how to reach it, first rejecting compulsory quotas and then squabbling with each other over how to redistribute them.
Luxembourg, which holds the rotating six-month presidency of the EU, said the justice and home affairs ministers had agreed to relocate 32,256 Syrians, Eritreans, Iraqis and Somalis who had landed in Greece and Italy.
"The first individuals can be relocated as of October this year," said Jean Asselborn, Luxembourg's foreign minister who is also responsible for migration.
The ministers also agreed to relocate 22,504 Syrian refugees currently living in camps outside the EU - actually exceeding their target for refugees of 20,000.
"The European Union will not become a fortress," Asselborn said.
More than 1,900 migrants have died this year making the perilous journey across the Mediterranean to Europe, out of around 150,000 people who have made the crossing, the International Organization for Migration said earlier this month.
The migrants are seeking refuge from conflicts and poverty in Africa and the Middle East.
Some governments - including those in central and eastern Europe - objected to earlier EU proposals to establish quotas on migrant arrivals.
EU sources said the countries that were most reluctant to admit migrants were Hungary, Austria, Slovakia, Slovenia, the Baltic countries and Spain.
Hungary refused to admit both migrants seeking asylum and refugees who had already been approved for asylum, according to EU figures. Austria refused to accept asylum seekers but agreed to take in 1,900 refugees.
Asselborn harshly criticized some countries without naming them, saying the figures were "perhaps disappointing, in some instances even embarrassing."
The tiny duchy of Luxembourg agreed to admit 320 asylum seekers and 30 refugees.
Rihards Kozlovskis, the interior minister of the Baltic state of Latvia, said his country was reluctant to admit migrants partly because it feared a surge of refugees from nearby Ukraine, which is embroiled in an armed conflict.
Latvia offered to take 200 asylum seekers and 50 refugees.
Topping the list was Germany which offered 10,500 places and 1,600 for asylum seekers and migrants respectively, followed by France, which will take in 6,752 asylum seekers and 2,375.
Britain, Denmark and Ireland were allowed to opt out of the programme under EU treaties.
But Ireland agreed to take in 600 asylum seekers and 520 refugees.
Denmark and Britain refused to admit asylum seekers but agreed to accept 1,000 refugees and 2,200 refugees respectively.
Italy, Greece and Malta have borne the brunt of the migrant influx.
Italian Prime Minister Matteo Renzi has repeatedly urged his European Union peers to do much more to ease the burden.
At the EU leaders' summit in June, Renzi was said to have lashed out at his colleagues after mandatory quotas were rejected, reportedly saying that "If that is your idea of Europe, you can keep it."
As well as migrants crossing by sea, thousands more have crossed into Europe by land, many of them through Hungary, which said last month it would build a four-metre (13-foot) high fence along its border with Serbia to keep out migrants.