A Moroccan computer engineer appeared in court on Friday charged with setting up a Facebook account in the name of King Mohammed's brother.
Fouad Mortada, 26, could face jail on the charges of falsifying computer data and imitating Prince Moulay Rachid on the social networking site without his consent.
Relatives said he was motivated by admiration for the 37-year-old prince, who is second in line to the throne.
Mortada said he was blindfolded and taken to an unknown building where he was beaten, spat on and insulted, according to a Web site set up by his supporters (www.helpfouad.com).
"This is a nightmare," Mortada's uncle Mohamed El Yousfi told Reuters. "Fouad is threatened, as well as his job and his family. He had no evil intent to damage the royal family, which he respects. He has done nothing wrong."
Newspapers quoted Mortada as telling the judicial police he had set up the Facebook account to give him a better chance of romantic encounters. Defense lawyer Ali Ammar said that was untrue.
"He said that to stop being tortured," Ammar said. "The police wanted to know if there was any relation between Fouad and terrorist groups seeking to harm the royal family but they found nothing of the kind."
A source close to the security services told Reuters Mortada was arrested at the request of the judicial authorities and under their supervision.
"Concerning the accusations of torture, the security services deny this. He was very cooperative," the source said.
Defense lawyer Ammar said he asked the judge to release Mortada during his trial, which is due to resume on February 22.
"Fouad is a computer technician," said his brother Ilyas. "If his intentions were bad, why would he use his own computer to set up the account knowing full well that someone could trace him back to his IP address?"
He said thousands of people had set up accounts on Facebook and other sites under the name of famous people they admired.