The bill's opponents also called for more humane treatment of immigrants who can face great hardship in some countries.
 
Detention period criticised
 
French socialist Martine Roure said in a debate: "The directive is not adequate in terms of protection of fundamental rights.
 
"It will not allow for the improvement of detention conditions in the EU."
 
Her group called for a maximum three-month detention period, with an extra three months in special cases.
 
The European Council on Refugees and Exiles said: "We consider that systematic detention of persons who have committed no crime is inhumane and unwarranted."
 
Dragutin Mate, the interior minister of Slovenia, which holds the rotating EU presidency, backed the draft law, saying it improves the situation of vulnerable people and children.
 
The European commission proposed a separate programme whereby EU nations would accept some asylum seekers from third countries swamped with refugees.
 
It also proposed an EU asylum office.
 
"There are a lot of Iraqis in Jordan, for example. We should be able to help those refugees and perhaps, one day, enable them to go back to their country," said Jacques Barrot, the EU commissioner responsible for immigration matters.
 
Close vote
 
The rules are an effort to craft a common asylum and immigration policy by 2010.
 
The bill states EU nations should grant immigrants basic rights, including access to free legal advice, food and shelter, and prohibit the expulsion or detention of unaccompanied children.
 
According to the bill, once illegal immigrants are found by the authorities, they will first be allowed to leave voluntarily for up to 30 days.
 
If there is a risk they will abscond, they can be put in custody for up to six months while their deportation is being processed.
 
There can be a 12-month extension in specific cases, such as when illegal immigrants do not co-operate with authorities.
 
The agreement on the rules among EU governments took more than two years to craft.
 
At present, there is no common policy on expelling illegal immigrants, and detention periods vary from 32 days in France to indefinite custody in Britain, the Netherlands and five other countries.
 
The EU estimates there could be up to eight million illegal immigrants in the bloc.
 
A cliffhanger vote had been anticipated in the European Parliament, with conservative and liberal democrat politicians backing the proposed rules.
 
The reforms will not automatically apply in Britain, Ireland, and Denmark, because they have negotiated opt-outs.