Washington (AFP) - US President Donald Trump wished Muslims "a joyful Ramadan," on Friday, urging them to use the holy month to reject violence by Islamist extremists.

"On behalf of the American people, I would like to wish all Muslims a joyful Ramadan," said Trump, who is winding up a first overseas trip as president that included a stop in Saudi Arabia.

"This year, the holiday begins as the world mourns the innocent victims of barbaric terrorist attacks in the United Kingdom and Egypt, acts of depravity that are directly contrary to the spirit of Ramadan," said the US leader, who campaigned last year on a pledge to ban Muslims from entering the United States.

"Such acts only steel our resolve to defeat the terrorists and their perverted ideology," he said in his message to the world's estimated 1.6 billion Muslims.

Trump said that when he met dozens of leaders of Muslim countries in the Saudi capital Riyadh, he had vowed to stand with them to counter "terrorism and the ideology that fuels it."

"During this month of Ramadan, let us be resolved to spare no measure so that we may ensure that future generations will be free of this scourge and able to worship and commune in peace," said Trump, whose revised travel ban on half a dozen Muslim-majority countries was once again rejected by a US court this week on grounds of religious discrimination.

"At its core, the spirit of Ramadan strengthens awareness of our shared obligation to reject violence, to pursue peace, and to give to those in need who are suffering from poverty or conflict," he said.

During Ramadan, Muslims around the world abstain from eating, drinking, smoking and having sex from dawn to dusk. The month is sacred to Muslims because tradition says it marks the period when the Koran was revealed to the Prophet Mohammed.

The presidential statement concluded by saying, "I extend my best wishes to Muslims everywhere for a blessed month as you observe the Ramadan traditions of charity, fasting, and prayer. May God bless you and your families."