WASHINGTON (AP) _ A former Peruvian Embassy official who embezzled between $7 million and $8 million and spent it on cocaine, prostitutes and racehorses was sentenced Wednesday to eight years in prison.

U.S. District Judge Harold H. Greene ordered the maximum sentence for Enrique Villagarcia, who until last year was the chief financial officer of the Peruvian Naval Commission, a component of the country's embassy here.

''You were involved in very heinous conduct that went on for a long time. There is no excuse for it,'' Greene said.

Villagarcia, 48, pleaded guilty in January to 112 charges of wire fraud, interstate transportation of stolen securities and money laundering in the theft of $2.3 million of funds from the Peruvian Naval Commission from February 1988 through March 1992.

He left work and dropped from sight in April 1992 and was arrested last December.

He entered the plea in an agreement with U.S. prosecutors to cooperate with their investigation in exchange for a promise that he would not be extradited to Peru.

However, Eric Marcy, an assistant U.S. attorney, and James Frick, a lawyer for the Peru government in the case, told Greene that key documents in Villagarcia's possession tracing the specific amounts taken since 1982 and where they went have not been located.

''I can't say that he's not cooperating,'' Frick said of Villagarcia. ''But we're having a very difficult time conducting an investigation that would be relatively simple if we did have the documents that he had.''

Greene, in stretching the sentence out by several months, noted that Villagarcia did not turn over the most incriminating documents until after U.S. prosecutors had arranged a non-extradition agreement with Peru.

''It was not my intent to delay things or obstruct the work of the prosecutors,'' Villagarcia told the judge through a interpreter. ''I was just trying to protect myself, because I know my life will be in danger if I return to Peru.''

According to the indictment, Villagarcia used his position to transfer money from the Peruvian Naval Commission's bank account here to a bank in Potomac, Md., and used some of those funds to buy a large house.

From the Potomac bank account, he also bought two racehorses, speculated in precious metals and the stock market and covered bets at the Laurel, Md., race track, according to government officials.

''It was not my intent to cause the great damages involved,'' Villagarcia told the judge. ''The only explanation - not an excuse - I can find is that I was weak and was in an environment that I had never seen before.''

A former captain in Peru's navy, Villagarcia said he had sought assignment to Peru's Washington embassy in 1979 in order for his wife to get cancer treatments.

''I understand weakness, but weakness is not an excuse to break the law,'' Greene replied. ''What we have here is a man who had tremendous advantage. Most of the money that was stolen did not go to his wife and his family. It went to cocaine, to gambling, to prostitutes and to the stock market.''