Any illusion that the 1986 election may have created about Mahathir's political dominance was short-lived. In 1987, he was challenged for UMNO's presidency, and effectively the prime ministership, by Tengku Razaleigh Hamzah. Razaleigh's career had gone backwards under Mahathir, being demoted from the Ministry of Finance to the Ministry of Trade and Industry. Razaleigh was supported by Musa, who had resigned as deputy prime minister the previous year. While Musa and Mahathir were originally close allies, the two had fallen out during Mahathir's premiership. Musa claimed that Mahathir no longer trusted him. Razaleigh and Musa ran for the UMNO presidency and deputy presidency on a joint ticket against Mahathir and his new choice for deputy Ghafar Baba. The tickets were known as Team B and Team A, respectively. Mahathir's Team A enjoyed the press's support, most party heavyweights, and even Iskandar, now the Agong. However, some significant figures, such as Abdullah Badawi supported Team B. In the election, held on 24 April 1987, Team A prevailed. Mahathir was re-elected by a narrow margin, receiving the votes of 761 party delegates to Razaleigh's 718. Ghafar defeated Musa by a slightly larger margin. Mahathir responded by purging seven Team B supporters from his ministry. At the same time, Team B refused to accept defeat and initiated litigation. In an unexpected decision in February 1988, the High Courts ruled that UMNO was an illegal organisation as some of its branches had not been lawfully registered.