MANILA (Reuters) - The Philippines’ highest court has ruled an American soldier convicted of raping a Filipina in 2006 must be placed in government custody, scrapping a deal between the two countries that allowed detention inside the U.S. embassy.

The Supreme Court, in a majority vote taken on Tuesday but announced only on Wednesday, upheld a decade-old security treaty between Manila and Washington. It also said the treaty was clear on the detention “by Philippine authorities” of any U.S. personnel serving sentences.

Jose Midas Marquez, a court spokesman, said the U.S. Marine could remain at the U.S. embassy until final arrangements have been made for his detention in a Philippine facility.

He said the court had ordered the government to begin talks with U.S. officials on Lance Corporal Daniel Smith’s transfer to Philippine custody.

The court nullified two executive agreements signed by Philippine Foreign Minister Alberto Romulo and U.S. Ambassador Kristie Kenney in December 2006 that allowed the transfer of Smith to the embassy premises.

“Agreements on the detention of the accused in the United States embassy are not in accord with the VFA (Visiting Forces Agreement) itself because such detention is not by Philippine authorities,” the judges said in a 19-page decision.

The U.S. Embassy in Manila said in a statement it has taken note of the court’s decision and would refer the matter to legal experts in Washington. It did not give further comments.

In November 2006, a local court found Smith guilty of raping a Filipino woman inside a former American navy base northwest of the capital Manila while on break at the end of annual U.S.-Philippine military exercises in 2005.

Smith was then sent to a local prison but was transferred shortly after to the U.S. embassy in Manila following the December 2006 agreements between Manila and Washington.

On Wednesday, left-wing activists protested against Smith’s continued detention at the U.S. embassy, questioning the validity of the 1998 security agreement that allowed U.S. troops to train Philippine soldiers in the country.

The Philippines is one of America’s closest allies in the region and was a colony for nearly 50 years until 1946. American troops retained a presence in forward bases until 1992 when Philippine senators voted to terminate a basing agreement.