JAKARTA, Indonesia — Sweeping legislation that would have criminalized sex between unmarried people, including gays and lesbians, was pushed back on Friday by Indonesia’s president, Joko Widodo, days before it had been expected to pass.

The measure, aimed at overhauling Indonesia’s penal code, had appeared likely to win approval next Tuesday from the country’s outgoing Parliament, with Mr. Joko’s blessing.

But after an outpouring of opposition to many of its provisions from rights activists, women’s groups, legal experts and other Indonesians, Mr. Joko announced that he had asked lawmakers to drop the legislation and leave the matter for the next Parliament, which will be seated in October.

“After examining input from various groups who objected to some of the substance of the criminal bill draft, I concluded that there were still materials that needed further study,” Mr. Joko told reporters at the presidential palace in Bogor, south of Jakarta.