The Afghan president, Hamid Karzai, has backed away from a law that would have silenced victims of domestic violence, forced marriage and child abuse, after a campaign by Afghan activists and western governments.

The new criminal prosecution code, backed by a prominent opponent of women's rights, banned relatives from testifying against each other. In a country where forensic evidence is relatively undeveloped, that would halt prosecution in most cases of violence against women.

On Monday the cabinet ordered changes to the brief section of the law that had caused the outcry, said Karzai's spokeswoman Adela Raz. "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 this month.

"Who says advocacy and lobbying does not work? It does and we have seen results always. Here is one of that," tweeted the campaigner Samira Hamidi. The European Union welcomed Karzai's decision to "stop [a] setback for women's rights".

Raz denied that the president – who is at odds with the US over issues ranging from the election to the long-term presence of foreign troops – had been slow to act. The draft had been held up by bureaucracy, and the president moved to block it 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."

But the cabinet order may not signal an end to the law. An aide to the justice minister, who gave his name only as Popal, said the ministry would make amendments as ordered and then send the criminal prosecution code back to parliament.

Conservatives in the law-making body had already quashed an earlier effort to water down the legislation, which would have barred forcing relatives to testify rather than any family testimony. The same block could potentially oppose the new changes, and may have some allies in the ministry.

Shortly before news of the cabinet order spread, a justice ministry official told the Guardian that western embassies had simply "misunderstood" the law, and that he expected the confusion would be resolved soon and without any changes needed.

Heather Barr, Afghanistan researcher at Human Rights Watch, said: "We are cautiously optimistic after hearing statements from the palace. We need to see the exact language before we can know whether it will really fix the problem. Unfortunately, there are two major problems with this law, and the government has only shown interest in fixing one."

Allowing all relatives to decline testifying goes far further than protections in most countries, where only spouses can avoid giving testimony. There is also no definition of relatives in the law, so particularly in villages linked by complex ties of marriage and blood it could potentially cover dozens or even hundreds of potential witnesses.