European Union countries are closing in on an agreement Thursday to crack down on migrants who have been refused entry into the bloc so they can be swiftly sent home.

A key issue will be to ensure there are tougher measures to put those who have to leave in pre-departure detention to make sure they don't disappear to live illegally in EU nations.

More than 500,000 people have arrived this year seeking sanctuary or jobs, sparking the EU's biggest refugee emergency in decades.

But of people who fail to obtain asylum or residency in the 28-nation EU, less than 40 percent actually go back. It is seen as a major flaw in the EU's common migration policy.

At Thursday's meeting in Luxembourg, EU interior ministers will agree that "all measures must be taken to ensure irregular migrants' effective return," according to a draft statement seen by The Associated Press.

Those measures include the "use of detention as a legitimate measure of last resort."

The EU has common asylum rules and legislation for returning people not permitted to stay, but the rules have rarely been enforced with any consistency.

With thousands of people arriving daily, border and reception facilities have been stretched to breaking point. Ensuring returns is seen as one way to ease the pressure.

According to the draft statement, EU countries plan to spend more than 800 million euros ($900 million) up until 2020 on returning people who enter Europe illegally.

Better use will be made of Europe's visa and fingerprint databases and countries will ensure that all decisions to send people home are entered into the Schengen passport-free area's computer system.

The ministers will welcome a proposal for the Frontex border agency to deploy "rapid return intervention teams," and give Frontex more powers to organize returns jointly among member nations.

Countries will agree to "reinforce their pre-removal detention capacity to ensure the physical availability of irregular migrants for return" — long-hand for building more detention centers to lock people up in so they can be sent home more easily.

The European Commission will assess whether countries are applying the return rules efficiently and consistently, according to the draft.

The member states also want the commission to press developing nations with which the EU has trade and aid deals to take back nationals who have no right to stay in the EU.