A custody agreement was reached Tuesday between the families of Jared Remy and Jennifer Martel — the woman he is accused of killing — which settles a battle over the fate of Remy and Martel’s 5-year-old daughter.

Attorneys for both families announced the agreement after a brief court hearing.

The agreement, which was impounded by the Middlesex County Probate Court, settles the dispute between Martel’s parents and brother, and Jerry Remy and his wife, Phoebe.

The girl, Arianna, has been in foster care while the families, including Jennifer Martel’s brother Brian, argued about her eventual custody.

“The parties came to an agreement that they’re all satisfied with, and under this agreement Arianna will spend time with all three families,” said Jerry Remy’s attorney, Sandy Durland. “The child is being cared for. She is a very lucky child that three families are so interested in her welfare.”

Red Sox broadcaster Jerry Remy was present for the court hearing but declined to talk to reporters.

Arianna was said to be present in Jared Remy and Jennifer Martel’s Waltham home when Martel was killed last August. Jared Remy has pleaded not guilty to first-degree murder charges.

“Arianna will be in the guardianship of the Martel family members, and she will also spend time with the Remys,” said attorney Susan Finegan, who represents Martel’s parents.

An independent review criticized prosecutors’ handling of abuse allegations against 35-year-old Jared Remy. He was released from custody after allegedly pushing 27-year-old Martel into a mirror two days before the killing.