A New Jersey judge has ruled that a gestational surrogate who gave birth to twin girls is their legal mother, even though she is not genetically related to them.

The ruling gives the woman, who carried the babies in an arrangement with her brother and his male spouse, the right to seek primary custody of the children at a trial in the spring.

The case illustrates the legal complexities of gestational surrogacy, in which a woman carries unrelated embryos created in a petri dish. A gestational surrogate in Michigan recently obtained custody of twins she carried, but courts in several other states have upheld the rights of people who contracted with gestational surrogates.

Prof. Charles P. Kindregan, an expert in reproductive technology law who teaches at Suffolk University Law School in Boston, said the New Jersey ruling, which was made Dec. 23 but released to the parties in the case this week, could expand the rights of gestational surrogates if it stood.