A High Court judge was ordered to step down from a multi-million pound divorce case for saying a Saudi sheikh might "depart on his flying carpet".
Lord Justice Ward said not all laughter in court was a bad thing
Mr Justice Singer said Sheikh Khalid Ben Abdfullah Rashid Alfawaz might dodge costs and his evidence was "gelatinous...like Turkish Delight".
The judge apologised for what he said were his poorly chosen remarks.
The Court of Appeal said it was "a singularly unsatisfactory, unfortunate and embarrassing matter".
The sheikh asked Mr Justice Singer to recuse - or disqualify - himself after a series of remarks made by the judge in a private hearing that the sheikh believed showed bias against him.
As well his flying carpet and Turkish Delight comments, the judge said the sheikh should be available for hearings at this "relatively fast-free time of the year", and that he should appear so that "every grain of sand is sifted".
After Mr Justice Singer refused to recuse himself, the sheikh brought the case to the Court of Appeal.
In handing down the appeal court's ruling, Lord Justice Ward said: "For my part I am totally convinced that they were not meant to be racist and I unreservedly acquit the judge of any suggestion that they were so intended.
"Unfortunately, every one of the four remarks can be seen to be not simply colourful language as the judge sought to excuse them but...to be mocking and disparaging."
Lord Justice Ward added: "Making every allowance for the jocularity of the judge's comments, one cannot in this day and age and in these troubled times allow remarks like that to go unchallenged."
In a statement after the ruling, Mr Justice Singer said: "A judgment handed down in the Court of Appeal today concluded that remarks made by me in the case of El Farargy v El Farargy and others were regrettable, unacceptable and might be perceived as racist jokes.
"I wish publicly to apologise to Sheikh Khalid Ben Abdullah Rashid Alfawaz for these remarks, which were not intended to be racially disparaging.
"My comments were poorly chosen. They were not intended to be racist, nor have I ever intended any disrespect or disregard for the tenets of Islam, or for the Sheikh's Saudi nationality and Arab ethnicity."
The contested statements were made during a hearing in September last year over a claim by Wendy Ann El Farargy, 59, for a divorce settlement which is being bitterly contested by her husband, 67-year-old Nael Mahmoud El Farargy.
The £1.7m family home in Cobham, Surrey, was bought in the name of a British Virgin Island company, which the sheikh claims to own.
The sheikh's claim of ownership is vehemently refuted by the wife, but solidly backed by the husband.