The Afghan president, Hamid Karzai, has blocked a law that would silence victims of domestic violence, forced marriage and child abuse and demanded major revisions after a campaign by Afghan activists and western diplomats.

The legislation bans relatives from testifying against each other, and in a country where forensic evidence is relatively undeveloped, that would effectively halt prosecution in even the most vicious cases of violence against women, including those mutilated by their husbands or attacked by brothers and fathers.

The provision was inserted into a new criminal prosecution code, much needed and years in the making, at the last minute. It was steered through parliament by a prominent opponent of women's rights, and conservative MPs resisted efforts to moderate the strict controls.

They apparently also had backing from some sections of government; early on Monday, a justice ministry official told the Guardian that western embassies had simply "misunderstood" the law, and that he expected the confusion be be resolved soon and without any changes needed.

But just a few hours later, a cabinet meeting chaired by Karzai ordered alterations to the brief section of the law causing the problems, his spokeswoman Adela Raz said. "At the meeting, His Excellency the President, and the cabinet, decided that article 26 needs to be amended."

She declined to say how the law would be altered, but the public repudiation of what would have been a devastating step backwards for Afghan women was welcomed by activists and diplomats. They had mounted a vigorous lobbying campaign, both in public and behind the scenes, since the legislation first came to light earlier this month.

"Who says advocacy and lobbying does not work? It does and we have seen results!" campaigner Samira Hamidi said, celebrating on Twitter. The European Union welcomed Karzai's decision to "stop [a] setback for women's rights".

The United States, which had previously issued only a brief statement of concern about the law, welcomed Karzai's decision as a "response to the concerns expressed by many Afghans and their international partners".

Five years ago, after a similar campaign against a family law that appeared to allow marital rape, the Afghan president ripped up the legislation and shepherded a more moderate version through the houses of parliament.

Raz denied that the president, currently at odds with the US over issues from the election to the long-term presence of foreign troops, had been slow to respond to the latest law in response to foreign or domestic pressure. The draft had been held up by bureaucracy, and Karzai demanded changes as soon as it reached his desk, she said.

"As soon as it arrived, it was brought to the cabinet as any law would be for discussion, and like anyone else who is concerned about women's rights, they responded," she said, adding that Karzai had a track record of supporting women. "In the past you have seen that the president is someone who has made sure women's rights are protected according to the laws of the country."

Whatever his personal views, Karzai has presided over a strengthening of factions opposed to women's rights during his latest term in office. In the last year alone parliament has blocked a law to curb violence against women and cut the quota for women on provincial councils, while the justice ministry has floated a proposal to bring back stoning as a punishment for adultery.

Activists also say the change to the law as currently planned would still leave women more vulnerable than they are now. It allows relatives to testify against each other if they wish but does not grant any legal rights to call them to the stand. An amended draft in circulation now says that relatives of the accused have a right "not to answer questions", according to an international diplomat following the case.

Protections in most countries exempt only husbands and wives from a legal obligation to testify against each other, while the new Afghan law covers a very wide range of relatives, from a mother's great-uncle to a brother's grandchildren. Especially in close-knit villages, this could potentially allow dozens of key witnesses to avoid giving evidence.

"We are cautiously optimistic after hearing statements from the palace," said Heather Barr, Afghanistan researcher at Human Rights Watch, which first raised concerns about the law. "We need to see the exact language before we can know whether it will really fix the problem.

"President Karzai's decision today is an indication that this kind of international reaction still makes a difference, and we would beg diplomats not to sit by next time there is an attack on women's rights, because there will be one," she added.

However, along with the demands to protect modest gains in women's rights since the fall of the Taliban, there is also some pressure for a fast resolution of the current standoff, because Afghanistan is in desperate need of a new criminal prosecution code.