The United Nations Secretary-General Kofi Annan has told the BBC the US-led invasion of Iraq was an illegal act that contravened the UN charter.
He said the decision to take action in Iraq should have been made by the Security Council, not unilaterally.
The UK government responded by saying the attorney-general made the "legal basis... clear at the time".
Mr Annan also warned security in Iraq must considerably improve if credible elections are to be held in January.
The UN chief said in an interview with the BBC World Service that "painful lessons" had been learnt since the war in Iraq.
"Lessons for the US, the UN and other member states. I think in the end everybody's concluded it's best to work together with our allies and through the UN," he said.
He said he believed there should have been a second UN resolution following Iraq's failure to comply over weapons inspections.
And it should have been up to the Security Council to approve or determine the consequences, he added.
When pressed on whether he viewed the invasion of Iraq as illegal, he said: "Yes, if you wish. I have indicated it was not in conformity with the UN charter from our point of view, from the charter point of view, it was illegal."
Mr Annan's comments provoked angry suggestions from a former Bush administration aide that they were timed to influence the US November election.
"I think it is outrageous for the Secretary-General, who ultimately works for the member states, to try and supplant his judgement for the judgement of the member states," Randy Scheunemann, a former advisor to US Defence Secretary Donald Rumsfeld told the BBC.
A UK foreign office spokeswoman said: "The Attorney-General made the government's position on the legal basis for the use of military force in Iraq clear at the time".
Australian Prime Minister John Howard also rejected Mr Annan's remarks, saying the legal advice he was given was "entirely valid".
The BBC's Susannah Price at UN headquarters in New York says Mr Annan has made similar comments before.
He has said from the beginning the invasion did not conform with the UN charter - phrasing that was seen as a diplomatic way of saying the war was illegal.
Our correspondent says Mr Annan's relationship with the US might be made a little uncomfortable for a while following his comments, but both sides are likely to want to play it down.
US President George W Bush is due to speak at the UN General Assembly next week.
Mr Annan also said in the interview the UN would give advice and assistance in the run-up to the elections, but it was up to the Iraqi interim government to decide whether such a vote should go ahead.
He warned there could not be "credible elections if the security conditions continue as they are now".
The UK foreign office spokeswoman said there was a full commitment to hold elections in January.
Election and political party laws had already been passed and an independent electoral commission established.
"The task is huge and the deadline tight, but the Iraqi people clearly want elections," she said.
On Wednesday, the head of the British army General Sir Mike Jackson said national elections in Iraq were still on track.
On Monday, Iraq's interim Prime Minister Iyad Allawi said elections must go ahead as planned although he conceded the violence might stop some Iraqis voting.
However, a day later a car bomb close to an Iraqi police station in central Baghdad killed 47 people and gunmen opened fire on a police minibus in Baquba, killing 12.