Germany has blocked a bill calling for tougher rules on migration after a close vote in the country's parliament.