The former MP George Galloway has issued a court apology and agreed to pay damages to his former assistant Aisha Ali-Khan over claims that she helped her former police officer husband run a dirty tricks operation against him and his Respect party.

Galloway, who was beaten into a humiliating seventh place in last month’s election for London mayor, formally withdrew claims he made in 2012 that Ali-Khan helped her former husband, Afiz Khan, to spy on him when Khan was a senior Metropolitan police officer.

His lawyer, Adam Speker, apologised to Ali-Khan at an open hearing at the Royal Courts of Justice in front of Mr Justice Warby.

Galloway, who was not in court, has also paid a five-figure sum in damages to settle the claim. The case represents a rare legal blow for Galloway after a string of libel victories.

Galloway made the libellous claims in a blogpost in October 2012. The court heard that they were then repeated by his spokesman in comments to the Mail on Sunday.

Ali-Khan’s lawyer, Mark Lewis, told the court that the paper then falsely claimed that Ali-Khan and her then husband had “conspired to run a dirty tricks campaign against the defendant [Galloway] and the Respect party”. Afiz Khan was at the time a senior officer in the Metropolitan police’s counter-terrorism unit, SO15

Lewis added that the paper also said “the claimant had been used as a police agent and that the claimant had slept with the officer at the defendant’s home”.

Lewis told the court: “She was not involved in leaking information to national newspapers or acting as a police agent. She had not slept with the officer, with whom she was married in a sharia law ceremony, at the defendant’s home.”

In a brief statement, Galloway’s lawyer withdrew the claims. Speker said: “The defendant accepts these [articles] contain defamatory accusations for which, through me, he apologises. He now withdraws these allegations. He has made payment for damages and agreed to pay legal costs.”

Galloway and Ali-Khan both agreed not to make any further comment.

Aisha Ali-Khan. Photograph: David Sillitoe/The Guardian

“All we are allowed to say is that we are very happy with the settlement,” Lewis told the Guardian outside the court standing next to a smiling Ali-Khan.

Asked how much Galloway had paid to settle the claim, Lewis said: “The Huffington Post says it is a five-figure sum. I’m not demurring from that. The last two figures aren’t pennies.”

The case is the latest in a number of legal battles involving Ali-Khan. In 2014, she pleaded guilty to encouraging Afiz Khan to access confidential emails.

She admitted encouraging Khan to obtain private information without consent while he was a senior detective. He had previously admitted to two counts of misconduct in public office, and was dismissed by the Metropolitan police.

Earlier in 2014, Ali-Khan was jailed for two findings of contempt of court. She was charged with failing to destroy explicit images of her husband and his estranged wife, and failing to sign an affidavit confirming that she had destroyed the images.

The former teacher was ordered to hand over or delete the illicit images after Khan’s estranged wife went to the high court to prevent the pictures being made public. However, she defied that court order and on 3 April was jailed for three months and ordered to pay about £10,000 in court costs.

However, at a subsequent court of appeal hearing the finding that she had failed to destroy the images was quashed but the finding that she failed to sign the affidavit was upheld. The sentence was reduced to 28 days.