Lawmakers have approved plans to ease the creation of offshore detention centres and impose tougher penalties on irregular migrants, in a vote that exposed deep divisions over EU migration policy.