SANTA MARIA, Calif. — Employees at Michael Jackson's ranch were instructed two years ago to prevent the departure of the boy who has since accused the singer of molesting him, a former security guard there testified on Wednesday.

The testimony by the former guard, Brian Barron, could lend credence to claims by the boy's mother that she and her children had been held against their will.

"'The kids are not to leave,"' Barron said, referring to Jackson's accuser and his younger brother, as he read from an entry made in February 2003 in a log kept in the gatehouse of the Neverland Ranch. The order, he said, was from the ranch manager, Joe Marcus.

A similar directive was written on a bulletin board in the ranch security office, Barron said. It referred specifically to the older boy, then 13, saying he was "not allowed off-property."

Prosecutors contend that the boy and his family were detained while Jackson's employees arranged to have them appear in a videotape that sought to refute reports that the boy might have been sexually abused.

A defense lawyer, Robert Sanger, showed on cross-examination that the boy, his two siblings and their mother were able to come and go at the ranch, apparently without hindrance, although they were invariably driven in and out by Jackson's employees or friends. It was not clear from the gate logs displayed in court whether anyone was supervising the movements, and Barron admitted there were unexplained gaps in the logs.

The boy's mother has often said that she was followed, watched and videotaped by Jackson employees and a private investigator at and near her home in Los Angeles after it became clear to her that Jackson feared that she might discuss in public his behavior with her son. Some of the surveillance tapes were shown in court in her five days on the witness stand. Her testimony ended on Tuesday.

The mother had also testified that she became so afraid after having received "death threats" from Jackson's employees that she and her children persuaded a ranch driver to help them "escape" in one of Jackson's Rolls-Royces in the middle of the night.

On Wednesday, Sanger asked the former guard to point to a log that referred to that night. The entry showed that the Rolls and its passengers were checked routinely out.

"There was no secret spiriting away," Sanger said, a remark that drew an objection from the prosecution. The judge, Rodney S. Melville of Santa Barbara Superior Court, sustained it as argumentative.

Earlier, Barron told jurors that after a search warrant was served on Jackson's ranch in November 2003, a Santa Barbara sheriff's detective asked him to return to work there and be an informer for the authorities. Barron, moonlighting on the ranch from his position as a police officer in Guadalupe, a few miles west of here, refused.

Prodded by Sanger, he said that in June 2002 Jackson's accuser crashed a golf cart into a fountain at the ranch. A security report said that the crash was caused by "reckless driving" and that the boy was warned if he did not slow down the cart, known as the Batman car, it would be taken from him.

Barron said children were treated well at Neverland.

"It was a fun place to go," he said. "They got to do what they wanted, for the most part."