BANGKOK — A protest in Malaysia against President Trump’s decision to designate Jerusalem the capital of Israel brought together political foes on Friday, illustrating how solidarity with Palestinians has united disparate forces in the Muslim world.

Prime Minister Najib Razak headlined a rally of more than 1,000 people in the Putra Mosque compound in Putrajaya, the country’s administrative capital.

Also in attendance were former Prime Minister Mahathir Mohamad, the 92-year-old opposition leader, who has led a campaign to oust the scandal-plagued Mr. Najib, his former protégé, and Khalil Abdul Hadi, the head of the youth wing of the country’s main Islamic party. Mr. Mahathir joined a prayer service at the Putra Mosque, along with other politicians.

“Today, regardless of our political beliefs, we gather to show that as Muslims in Malaysia we are united in opposing Jerusalem as Israel’s capital,” Mr. Najib said Friday.