Britain's exit strategy from Iraq suffered a setback yesterday when the country's parliament rejected a draft law paving the way for withdrawal of forces by the end of July. The reversal was embarrassing for both Gordon Brown and the Iraqi Prime Minister, Nouri al-Maliki, after the two leaders publicly declared last week that an agreement had been reached on the pullout.

Foreign Office sources admitted that unless the law receives formal Iraqi approval by the end of this month, when the United Nations mandate for the occupation expires, the vote could lead to British troops being confined to base, because they would not have the legal authority to do anything else in Iraq. However, officials attempted to dampen speculation that the resolution could have such a dramatic impact, and insisted that the problem was "procedural".

A Foreign Office spokesman said: "We have worked closely with the government of Iraq to ensure that there is a firm legal basis for the presence of our forces in 2009. We will now discuss with the government of Iraq what the vote in the Council of Representatives means for the proposed legal basis for the UK and other forces, and look at the options."

Download the new Independent Premium app Sharing the full story, not just the headlines

The possibility of British troops operating in a legal limbo from January was increased by Mr Maliki's refusal even to start talks with the UK until after the Iraqi parliament approved the US deal on 27 November. This reflected his anger at what he saw as Britain's surrender of Basra to Shia militias last year.

Early this month the Secretary of State for Defence, John Hutton, warned: "I won't hesitate to pull [British forces] out. They have to be [legally] protected, and the way things stand at the moment they will not be." His Conservative shadow, Liam Fox, said the Iraqi vote "raises serious questions". If another vote failed, Britain would have to ensure alternative arrangements were in place by the end of the month.

The immediate effect of the vote by the MPs to reject the draft law by 80 votes to 68 is that the UK, Australia, Romania, Estonia, El Salvador and Nato would not technically have legal authority for any use of force in Iraq, even in self-defence, after the end of the month. Yesterday's was the first reading of the bill in the Council of Representatives, or parliament. It is now due to be sent back to Mr Maliki's cabinet for amendments, with another vote due next week. Some MPs want the law dropped and replaced with an international agreement similar to the deal with the US, which lays down the terms for its withdrawal of 140,000 troops from Iraq by 2011.

Nassir al-Issawi, an MP allied to the radical Shia cleric Muqtada al-Sadr, who wants foreign troops to leave at once, said: "What the parliament did today, rejecting the bill, was a great national achievement. We believe that British forces and all other forces should pack their things."

Fariad Rawndouzi, a Kurdish MP, said many of his colleagues were also unhappy with the formulation of the bill, and wanted it to resemble the "status of forces" agreement between the US and Iraq more closely.

Senior officers at the British base in Basra said a team of Foreign Office lawyers was negotiating with the Iraqi government in Baghdad, and they still hoped an agreement would be reached. One official said: "There was always a feeling that this may go to the wire, and we must realise that it is all quite symbolic." There were no plans to start pulling out British troops immediately in the new year.

But Mr Maliki's casual assurance to Mr Brown when he visited Iraq last week that all would be well may cause embarrassment to both sides. Hakim Ali Ibrahim, an Iraqi political analyst, said: "Parliament wants to make a stand to show it should not be taken for granted. Perhaps Maliki and Gordon Brown should not have made such a big thing out of this before they were certain everything would go through smoothly. We have elections coming up, and the government has to do deals with the MPs."

The provincial elections in January, the first held under sovereign, rather than occupation, laws, will be followed by a referendum on autonomy for Basra province, which could have a crucial impact on the division of its oil riches.

There are fears that the militias will attempt to use the polls to infiltrate the city again, and yesterday General Raymond Odierno, the US commander of coalition forces in Iraq, visited Basra for an election security meeting with Major General Andy Salmon, the British commander in Basra.