The last things Michele Quiles saw were color photos of her two young daughters at a Chuck E. Cheese's birthday party. Then her ex-husband, Marlo Small, leaned over, put a gun to her temple and shot her to death.

A Fairfax County judge yesterday sentenced Small to 38 years in prison for the second-degree murder of Quiles in Annandale. Small, 31, apologized to Quiles's family, thanked a homicide detective for pursuing him for more than a year and pleaded with his family and Quiles's to resolve a bitter dispute over the care of his daughters.

Quiles, 24, was found slumped in the driver's seat of her car, parked on Americana Drive near Little River Turnpike, on April 24, 2002. The photos of her daughters were scattered at her feet, but she hadn't brought them to the sudden meeting that Small had arranged the night before. Prosecutors said Small lured Quiles to the meeting with the claim that their daughters, then ages 4 and almost 2, were ill.

Quiles and Small had split up a year earlier but agreed that the girls would stay with Small and his parents in Woodbridge to avoid disrupting their day-care routine. Then, in April 2002, Quiles had a job as a manager at the Eddie Bauer store in Fair Oaks Mall, a new apartment next to her mother and older sister, and a new boyfriend. She told Small she was going to seek custody of their daughters, prosecutors said. Soon after, she was dead.

Police quickly focused on Small as a suspect, and Detective Robert Bond arranged for a cooperating witness to tape phone conversations in which Small repeatedly implored the witness to give police a false alibi for Small, court records show. Bond obtained search warrants for Small's home and car and interviewed Small but did not file charges.

Small realized that Quiles's family was cooperating with Bond and tried to cut off visitation for the girls' grandparents. The Quileses sued in Prince William County and won monthly visits, but Small appealed.

Experts had said the Quileses probably would lose the case. Legal precedent establishes that a fit, competent parent may choose whom his children see or don't see. With Small not facing any charges connected to his ex-wife's death, domestic law experts said he probably would prevail and prevent the Quileses from seeing their grandchildren.

In July 2003, a Fairfax grand jury indicted Small on murder charges. A key hearing in the visitation case was scheduled for shortly after his arrest, but a Fairfax judge denied him bond. The visitation case was postponed until the murder case was resolved.

Small hired William B. Moffitt, a top Washington defense lawyer, who filed a flurry of pretrial motions. In October, with a trial date approaching, Moffitt went to Fairfax prosecutors and said his client wanted to enter a plea. In January, Small pleaded guilty to second-degree murder and using a firearm during a felony.

Instead of visitation, the Quiles family is seeking full custody of the girls, now 5 and 3. A preliminary hearing is scheduled in Prince William for later this month. Evelyn Small, Marlo Small's mother, declined to comment.

Both families packed the courtroom of Fairfax Circuit Court Judge Kathleen H. MacKay and stood along the back wall. Jeanne Quiles, the victim's mother, told the judge: "We can't sleep, we can't eat. All we do is think about her and the life she could have had."

Ruben Quiles, the victim's father, said, "We never expected to have to endure something like this, our youngest daughter ripped from us, and then our granddaughters ripped from us at the defendant's direction."

Marlo Small never looked up at the Quileses or his father as they testified. And he never turned to face the courtroom gallery as he read a three-page statement expressing his sorrow. He apologized to both families and to his children, who were not present, and said his ex-wife was "a good mother, friend, aunt and daughter. She was not meant to leave this earth the way that she did."

Small asked that both families work together to raise his children and "overcome my stupidity." After the hearing, Small's parents approached the Quileses and offered conciliatory words and hugs, though they still face a contentious custody case.

MacKay called the situation "a horrible case" and sentenced Small to the maximum 40 years on the murder charge but suspended five years. She imposed a three-year consecutive sentence on the gun charge.

Ruben Quiles said the judge "did what she could and tried to understand what parents go through. Out of all this misery, she did the best she could."

Marlo Small admitted killing Michele Quiles in 2002. Their families are fighting for custody of the children.