Mexico's supreme court has declared unconstitutional a key portion of a military law that broadened the influence of courts martial and angered civilian victims seeking justice.

Tuesday's 8-2 ruling said a provision of the code of military justice that claims authority over all crimes committed by soldiers on duty is incompatible with Mexico's constitution. The ruling said it violates a federal law stipulating that military courts should not expand their scope over civilians affected by a case.

The court ruled that soldiers arrested as suspects in the killing of Bonfilio Rubio, an indigenous man from southern Mexico, should be transferred to a civilian court. Rubio died in June 2009 after soldiers opened fire on a bus in which he was travelling at a checkpoint near the town of Huamuxtitlan.

"When a person outside the military is either the defendant or the victim, an ordinary judge has authority over this case, not a military judge. The constitution says it," Justice Luis María Aguilar said.

A part of the military code says all crimes committed by soldiers on duty are considered crimes against military discipline.

The provision has been subject to scrutiny because human rights activists claim it has long allowed security forces to take over cases and protect soldiers accused of abusing, torturing and executing civilians.

Rights groups and Mexican media obtained records showing that military prosecutors opened nearly 5,000 investigations into alleged violations of human rights between 2007 and April 2012, but only 38 service members were convicted and sentenced. The number of complaints has increased since the president, Felipe Calderón, deployed tens of thousands of soldiers to crack down on drug traffickers.

The inter-American court on human rights has urged Mexico to reform the code of military justice.

Nik Steinberg, the Mexico and Cuba researcher of Human Rights Watch, said: "This is the most important step the supreme court has ever taken toward ending the longstanding practice of sending abuses by soldiers to military courts."