A transcript of the speech was distributed to journalists in Manila on Monday.

“And there is the civil code, which states you can only marry a woman for me, and for a woman to marry a man. That’s the law in the Philippines.”

Mr. Duterte, who turns 72 next week, said he was only following what was in the books, asserting that he did not take issue with anyone’s sexuality. Two of his brothers-in-law, and some of his cousins, are gay, he said.

But he stressed: “Wherever God has placed you, stay there.” He noted that no one was empowered to “erase the great divide between a woman and a man.”

This stood in contrast to Mr. Duterte’s stance during the 2016 campaign, when he expressed support for possible legislation allowing same-sex marriage.

In a pre-election forum in January last year, Mr. Duterte endeared himself to progressives and the gay community when he was asked whether he would push for legislation to allow same-sex marriages, and he replied that he would. He said there appeared to be an “error in the Bible” when it said unions must be only between men and women.