The royal decree announced on Tuesday handed victory in that battle to the reformers, who had gained an advantage in recent years because of demographics, economics and the country’s young leadership, analysts said.

Saudi leaders, who have been criticized for the war in Yemen, the blockade of Qatar and a range of human rights issues, clearly hoped the step would help the kingdom’s reputation.

“There is no wrong time to do the right thing,” Prince Khalid bin Salman, the Saudi ambassador to Washington and a son of King Salman, told reporters after the change was announced.

The government also worked behind the scenes to control the message.

At least eight prominent women’s activists received calls and text messages from Saudi security officials warning them not to tweet or speak to the news media about the issue, according to three Saudi activists.

They presumed the government did not want to give credit to activists for prompting the change and spoke on condition of anonymity so as not to jeopardize the women — or themselves.

Many women cheered the decision, calling it a final victory in a long campaign for social change.

Manal al-Sherif, who was jailed for having posted videos of herself driving and who wrote a book about her activism, said her life had tracked the wider social changes in the kingdom.

Born into a poor conservative family in Mecca, Ms. Sherif, now 38, was taught that women were to remain at home and that good Muslims were to avoid “infidels” who did not share their faith, she said by phone from Australia, where she now lives.