The Anwar Ibrahim sodomy trials are a source of considerable political controversy in Malaysia. The first trial was held in 1998, and resulted in former Deputy Prime Minister Anwar Ibrahim being convicted, and given a nine-year prison sentence. This verdict was overturned in 2004, resulting in Anwar's release from prison.
 While being the leader of the Pakatan Rakyat opposition, Anwar was charged in 2008 with sodomising a male aide. He was tried in 2010 and 2011 and, in January 2012, was acquitted. In March 2014, the acquittal was overturned by the Court of Appeal, which convicted him and imposed a sentence of five years' imprisonment. Anwar appealed to the Federal Court, which in February 2015 re-affirmed the conviction and sentence. Anwar served the sentence in Sungai Buloh Prison in Selangor before being pardoned on 16 May 2018.
 In 1998, a book, 50 Dalil Kenapa Anwar Tidak Boleh Jadi PM ("50 Reasons Why Anwar Cannot Become Prime Minister") was circulated among members of the United Malays National Organisation (UMNO) General Assembly, containing graphic allegations as well as accusations of corruption against Anwar.
 Anwar was fired from the Cabinet on 2 September 1998, amid police reports that he was under investigation. The following day, he was expelled from UMNO. Munawar Anees, Anwar's former speechwriter, and Sukma Darmawan Sasmita Atmadja, Anwar's adoptive brother, were arrested under suspicion of engaging in homosexual acts. Five days later, they were given a jail sentence of six months after pleading guilty to "unnatural sex" with Anwar. They later recanted their confessions, and appealed the sentence, claiming to have been coerced into pleading guilty. Anees made a statutory declaration to that effect. However, Munawar's appeal was rejected by the High Court on 29 October 2008 upholding his guilty sentence. Two of Anwar's secretaries, Ezam Mohamad and Mohamad Azmin Ali, were both held separately as part of police investigations into the "50 Reasons" book. Both were later released.
 On 29 September 1998, Anwar appeared in court and pleaded innocent to charges of corruption and sodomy. A photo of Anwar with a black eye (incurred from a beating by then Inspector General of Police Rahim Noor) and one hand raised became a symbol of the political opposition in many reformasi posters.
 The black eye was explained by Mahathir Mohamad and Rahim Noor as being "self-inflicted" and caused by "pressing a glass over his eyes". Only after a Royal Commission was convened did Rahim Noor admit that he had administered the beating to Anwar. Rahim apologised for the incident in August 2005. Rahim Noor was eventually charged for the assault and was given a two-month prison sentence and fined 2,000 ringgit (SGD571.40).
 During the trial, a mattress was presented to court, supposedly stained with Anwar's semen. This was submitted as DNA evidence of Anwar's sexual acts. Anwar denied having anything to do with the mattress, although the DNA tests came out positive. Lim Kong Boon, a DNA chemist, testified during the trial that DNA taken from 10 of 13 semen stains on the mattress matched Anwar's DNA. The defense team implied that DNA samples may have been taken from Anwar, while unconscious, after his beating in police custody, to create false forensics evidence to frame Anwar; however, High Court Judge Augustine Paul accepted that DNA evidence.
 During the trial, Mahathir appeared on Malaysian television in a special appearance to explain the arrest of his deputy. This was one of several occasions in which Mahathir declared Anwar guilty of sodomy and homosexual acts, even as the trial still was underway. The government included the statements of the purported victims of Anwar's sodomy attacks, evidence that was widely considered to be tainted. Furthermore, the prosecution was unable to accurately decide on a date that the alleged acts of anal sex had occurred—the government originally alleged that the sodomy had occurred inside a building that had not been constructed at the time of the alleged event.[citation needed]
 Furthermore, the Attorney General's prosecution team (headed by Abdul Gani Patail) also submitted a scenario in which Munawar Anees took an overnight flight from Britain all the way to Malaysia to be sodomised by Anwar, and flew back to Britain after that. The infamous "stained mattress" that was taken in and out of court over 20 times throughout the duration of the trial, was supposedly the same one that Anwar did his homosexual acts and had extramarital sex on. However, according to the evidence, the sexual acts had taken place on the mattress a few years ago, and yet the DNA evidence obtained from it were rather recent in age.
 On 14 April 1999, Anwar was sentenced to six years in prison for corruption and, on 8 August 2000, nine years in prison for sodomy. The sentences were to be served consecutively, and Anwar was given no credit for the six months he spent in jail during the trial. The following year, Anwar's corruption conviction was upheld by Malaysia's Court of Appeal. In July 2002, Anwar lost his final appeal against the corruption conviction in the Federal Court. In September 2004 the Federal Court overturned his sodomy conviction.
 Both Amnesty International and Human Rights Watch expressed doubts about the fairness of the trials.
 Anwar's wife, Wan Azizah Ismail, subsequently formed Parti Keadilan Nasional (the National Justice Party, later known as Parti Keadilan Rakyat or the People's Justice Party), which based its platform on campaigning for Anwar's release and reformasi. At the following general election, the then-National Justice Party performed poorly in the election, only winning five parliamentary seats.
 On 28 June 2008, an aide to Anwar Ibrahim, Mohammad Saiful Bukhari Azlan, lodged a police report claiming that he had been forcibly sodomised by Anwar. When it was put to him that a 61-year-old man is unlikely to be able to physically overpower a 24-year-old man, Azlan changed his complaint to "homosexual conduct by persuasion". Sodomy, even if consensual, is punishable by up to 20 years' imprisonment and whipping under Section 377B of the Malaysian Penal Code. Anwar responded that the complaint was politically motivated and intended to discredit him, and called it a "complete fabrication" and asserted that he had an alibi. Anwar subsequently filed a lawsuit against Saiful. Anwar's wife, Wan Azizah Wan Ismail, accused the government of orchestrating the allegations, and alleged that the government was behind the accusations. Prime Minister Abdullah Ahmad Badawi denied the allegation.
 On 29 June, Anwar took refuge in the compound of the Turkish Embassy in Kuala Lumpur, and left the following day after receiving assurances of his safety by Malaysian police. Anwar promised to cooperate with the investigation, but stated he feared a repeat of the previous trial. On 9 July 2008, Anwar asked an Islamic court to investigate his former aide. Under Islamic law, anyone making accusations of a sexual crime, such as sodomy, has to produce four witnesses to back up their claim. The witnesses must be credible and male, or two women may stand in for one man.
 Malaysian police issued an arrest warrant on 15 July for Anwar Ibrahim, and investigating officer Jude Pereira signed and issued the letter requiring Anwar to appear at a police station for questioning before Wednesday at 2 pm local time. Counsel Nair said Anwar agreed to the new request for questioning, amid arrest under the Sodomy Act. Home Minister Syed Hamid Albar demanded that Anwar provide his DNA: "We have taken DNA (from the accuser) so we have to take Anwar's DNA also." On 16 July 2008 Anwar was arrested by a contingent of 10 police cars (half unmarked and half patrol) with 20 balaclava-clad masked commandos, under Section 377A of the Penal Code, outside his home on 16 July. He cut short an interview at the headquarters of the Malaysian Anti-Corruption Agency to meet the police deadline, whereupon he was arrested. Anwar complained he was locked up with hardened criminals overnight and forced to sleep on the cement floor. The bail required for Anwar's release was RM 10,000.
 Anwar was eventually released without charges filed, but had to post bail on 17 July, after overnight police detention and after recording his statement at the Kuala Lumpur police headquarters on 18 August 2008.
 In July 2008, Anwar produced a medical report that he argued demonstrated that he had not assaulted Saiful. Having produced the report, Anwar requested police drop their investigation into the alleged sodomy. Parti Gerakan Rakyat Malaysia on 20 July proposed that international experts be used in the investigation against Anwar, for Koh Tsu Koon opined this would prevent falsification of DNA samples. Deputy Police chief Ismail Omar said that the police will not use the 1998 DNA sample collected from Anwar. Kuala Lumpur Hospital Director Zaininah Mohammed Zain said Anwar was not stripped naked in his medical examination. In February 2010, Anwar appointed three DNA and forensic experts from overseas to help his defence.
 On 15 August 2008, Saiful swore on the Quran that he was sodomised by Anwar according to Federal Territory Mosque Imam Ramlang Porigi. Ramlang said that he was one of four imams present for the ceremony that was held between 6.15 pm and 6.20 pm.
 On 7 August 2008, Anwar pleaded not guilty to "unnatural sex" sodomy charge (defined as "carnal intercourse against the order of nature") at the Jalan Duta Court complex and released by Sessions Court Judge Komathy Suppiah on a personal bail bond of RM 20,000. In November, the judge in the Sessions court struck down the request by Attorney General of Malaysia Tan Sri Abdul Gani Patail to transfer the case to the High Court. The reason given was that the certificate signed by the AG was invalid. The judge fixed the court date at 10 November 2008.
 Anwar's sodomy trial, his second since 1998, began on 3 February 2010.
On 2 August 2010 his lawyers moved to have the charges dropped amid rumours that his accuser was having an affair with a member of the prosecution team. Anwar's defence had continually been refused access to clinical reports by the trial judge during the cross-examination of the HKL doctors who examined Saiful.
 The sodomy charges sparked numerous criticisms and expressions of concern from overseas. Political leaders from the United States, Australia, and other governments commented on the case, damaging Malaysia's reputation as a progressive, Islamic democracy. Amnesty International and other human rights groups condemned the charges against Anwar.
 Over 50 Australian Parliamentarians from the Government and the Opposition signed a letter formally requesting that Malaysia cease the trial of Anwar. Prime Minister Najib stated that the Australian lawmakers were likely not familiar with the details of the case.
 However, People's Union for Civil Liberties and International Commission of Jurists have stated that the appeal process was going smoothly and fair on both sides.
 Local reaction to the trial was split between supporters of different governmental factions. Opposition supporters believed there was a conspiracy to discredit him. Prominent opposition MP Karpal Singh suggested that Prime Minister Najib Tun Razak and his wife were behind the initiation of the sodomy charge. However, the police strongly disagreed, indicating that Anwar's arrest was supported by the evidence. A shared concern, such as that expressed by veteran UMNO leader Tengku Razaleigh Hamzah, was that the trial will "shame the country the world over". Malaysia's Foreign Ministry on 8 February 2010 cautioned foreign governments against involving themselves in the trial by commenting on or criticising the Malaysian legal system.
 On 9 January 2012, almost two years after the trial started, Judge Zabidin Mohamad Diah found Anwar not guilty of sodomy, after finding the DNA evidence submitted by the prosecution unreliable. His oral verdict concluded: "The court is always reluctant to convict on sexual offences without corroborative evidence. Therefore, the accused is acquitted and discharged." Anwar expressed surprise at the verdict and said: "Thank God justice has prevailed I have been vindicated." Information Minister Rais Yatim responded by claiming the verdict demonstrated the independence of Malaysia's courts. Mahathir Mohamad, the prime minister at the time of Anwar's first sodomy trial, said that the verdict vindicated the government and proved there had never been a conspiracy between the government and the judiciary to imprison Anwar. Saiful, the complainant, said after the verdict was delivered that he hoped that the prosecution would appeal against Anwar's acquittal.
 Anwar had spent the days before the verdict travelling Malaysia to gain support for the opposition. Approximately 5,000 opposition supporters rallied outside the court on the day the court delivered the verdict. Five people were injured in explosions in the area around the court complex, the cause of which could not be confirmed by police at the time.
 On 20 January 2012, the prosecution filed an appeal against Anwar's acquittal.
 The Court of Appeal overturned the acquittal of Anwar, upholding a government appeal. The court also convicted Anwar and sentenced him to five years' imprisonment. The decision came late on 7 March 2014 as Anwar prepared to contest a state by-election on 23 March he was expected to win, opening the way for him to become the chief minister of Selangor state, the country's main economic hub surrounding Kuala Lumpur. Human rights groups accused Malaysia's government of using an "anachronistic colonial-era law" that criminalises "carnal intercourse against the order of nature" to persecute 66-year-old Anwar, who leads a three-party opposition that is increasingly popular in the predominantly Muslim nation.
 Anwar lodged an appeal against the Court of Appeal's decision and, on 10 February 2015, the Federal Court re-affirmed the conviction and five-year sentence. The conviction was by a unanimous decision of the Federal Court. The lead prosecutor had called for the prison sentence to be increased, given that the maximum sentence is 20 years. As this was Anwar's final right of appeal, he was incarcerated immediately in Sungai Buloh Prison. Before leaving the court, Anwar criticised the presiding judges for "bowing to the dictates of the political masters". During the hearing he had praised the judges as "patient and attentive". His statement was supported by one of his lawyers, Ramkarpal Singh, who applauded the bench for hearing both submissions without fail and "the fact that this appeal is one of the longest in Federal Court history proved that we will obtain fair judgement."
 Human Rights Watch described the ruling as a "major setback for human rights in Malaysia". In an official response to the decision, the United States government stated, "The United States is deeply disappointed and concerned by the rejection of Anwar Ibrahim's final appeal and his conviction ... The decision to prosecute Mr Anwar, and his trial, have raised serious concerns regarding the rule of law and the independence of the courts". The office of Malaysia's Prime Minister Najib Razak responded to the ruling by stating that "Malaysia has an independent judiciary, and there have been many rulings against senior government figures".
 On 16 March 2015, Nurul Izzah Anwar, daughter of Anwar and a member of parliament, was arrested by the police for a speech she read in parliament that referred to the February 2015 ruling which upheld Anwar's sodomy conviction.
 On 16 May 2018, Malaysia's King, Sultan Muhammad V, officially pardoned Anwar after meeting with members of the pardons board and Prime Minister Mahathir Mohamad.
 Ummi Hafilda Ali, a Malaysian businesswoman, also became a witness in the Anwar Ibrahim sodomy trials in 1998. After accusing Anwar of adultery and sodomy, she later retracted her allegations.