Fabiola Morales and Kelly Costello with their dog, Blue, pose in December 2012 in Potomac, Md. (Katherine Frey/The Washington Post)

On Wednesday morning, Kelly Costello and Fabiola Morales were exhausted from staying up all night with their 5-day-old twins, but they turned on the TV in their Potomac home anyway, anxious to learn whether the Supreme Court had granted their other dearest wish: permission to stay together in the United States.

“When we heard the news, everyone in the family started crying with happiness except the babies. They slept right through it,” said Morales, 39, a registered nurse and immigrant from Peru. Although legally married to Costello since 2011, she faced the likelihood of being deported next year after her visa expires.

Now, as a result of the high court decision Wednesday that overturned a key element of the Defense of Marriage Act, thousands of bi­national same-sex couples such as Morales and Costello will be allowed to apply for permanent residency for the foreign-born spouse. The 1996 law denied federal benefits and immigration rights to gay spouses.

Lawyers at Immigration Equality, a nonprofit group that championed Costello and Morales’s case and lobbied for DOMA’s repeal, called the ruling an “extraordinary” victory for same-sex couples, including some who have spent years in legal limbo or have been forced to live in separate countries because one spouse was not a legal U.S. resident.

“This means that gay and lesbian couples across the country and the world can plan for their futures and not have to live with uncertainty month after month,” said Steve Ralls, a lawyer with the group. “Those who have been forced into exile can come home. We have a stack of green card applications ready to go, and we will submit one for Kelly and Fabiola tomorrow.”

Costello, 30, an elementary school teacher in Montgomery County, has lived with Morales for the past five years. After marrying in the District, they decided to start a family, even though Morales had no guarantee of remaining in the country. On Friday, Costello gave birth to their daughter Lucia and son Augustus at Holy Cross Hospital in Silver Spring, with Morales and both women’s mothers on hand.

“We are so excited and overwhelmed by everything. The babies are healthy, and now their mommy gets to stay in the United States,” said Costello, who brought the twins home from the hospital Tuesday. “Now we will finally have the security and stability we always wanted as a family.”

Ralls said about 36,000 couples in the United States would be immediately affected by the ruling. He said that even if a couple is living in a state that does not recognize same-sex marriage, the foreign-born spouse can be sponsored for residency if the couple was legally married in a state that does. Maryland and the District allow same-sex marriage; Virginia does not.

Morales said their quiet suburban lives had already undergone a huge change in the past week, with all-night feedings and unaccustomed domestic chaos. With Wednesday’s upheaval, she said, “our lives are now complete. Justice was done. We are very thankful, and our babies will be very proud of their country.”