As soon as Sam Wilson learned that his daughter had been taken from her mother by the District’s child welfare agency and placed in foster care, he demanded that the preschooler be allowed to live with him in District Heights.

Instead, the little girl spent the six months in foster care while Wilson, who had joint custody of his daughter, fought for his right to care for her.

Wilson and another father filed a lawsuit Wednesday in U.S. District Court, accusing the D.C. Child and Family Services Agency of violating their parental rights because they live in Maryland.

Attorneys for Wilson and Andre Adgerson of Temple Hills contend that city social workers should have handed their children over to them as soon as they were taken from their mothers. Instead, they say, the city misinterpreted a federal law designed to protect children from bad out-of-state foster homes and adoption placements by insisting that the fathers be investigated to be sure they were fit to care for their children. There was never a suggestion that they were not.

Had the fathers been D.C. residents, the complaint said, the child welfare agency probably would have released the children into their care within 72 hours.

“They are hurting children and wrong on the law,” said Judith Sandalow, executive director of the Children’s Law Center, which filed the complaint with the Arnold & Porter law firm.

About 12 families each year are affected by the city’s interpretation of the law, Sandalow said.

If a child is to placed in out-of-state care, the Interstate Compact on the Placement of Children requires that the state conduct an investigation of the proposed placement before the child is moved. The lawsuit argues that the law does not apply to parents.

“Acting without authorization, CFSA has arbitrarily added the word ‘parent’ to that part of its Policy Statement,” the complaint said.

Asked about the allegations, the D.C. attorney general’s office said in a statement that “the Office of the Attorney General will defend vigorously the District, the Mayor, and CFSA’s efforts to ensure that children are in a safe home.”

The District is not the only place where the law is misinterpreted, advocates said.

“This is actually a problem across the country,” said Vivek Sankaran, a University of Michigan law professor who has worked on cases such as Wilson’s and Adgerson’s for the past 10 years. A number of courts, in California, Washington state and Arkansas, for example, have ruled that the law does not apply to parents.

In the District, many children unnecessarily wind up in foster care for prolonged periods, Sankaran said.

Adgerson’s daughter was in foster care for a month. Like Wilson, Sandalow said, he had been an involved father since his daughter’s birth and shared custody with the child’s mother, who lived in the District.

Adgerson asked for full custody as soon as social workers deemed the mother neglectful. The child welfare agency told him that because he lived outside the District, the lawsuit says, it would have to request an investigation by Maryland authorities to see whether he was a fit parent.

Wilson fought for months to get his daughter back, attending numerous meetings and family court hearings, the complaint says. By the time he gained custody, she had spent her fourth birthday in foster care.