The daily fantasy sports companies DraftKings and FanDuel have agreed to merge after a turbulent year in which both of their values plummeted as several attorneys general questioned the legality of their games in their states.

The merger must be approved by regulators and will take time — the companies said they expected the deal to close in the second half of 2017. Until then, both sides will operate under their own brands.

The merger was one of necessity: Lobbying and legal costs had damaged both companies’ bottom lines to the extent that representatives of the companies last month asked the New York attorney general’s office to allow them to pay a combined $12 million settlement in installments after claims that they employed false and deceptive advertising practices, two people familiar with those negotiations said.

In recent weeks, according to these two people, FanDuel, based in New York, laid off more than 60 people, and both companies have acknowledged that they are months behind in their payments to vendors, especially to the array of public relations and lobbying firms that they have employed across the nation to persuade individual state legislatures to legalize daily fantasy games — the most critical component of rebuilding their business.