Daily fantasy sports sites DraftKings Inc. and FanDuel Inc. have agreed to set aside their bitter rivalry and become one as they face down regulatory and legal challenges to their business.

The two companies, which together spent upward of $500 million on advertising last year to try to build unique brands, had been talking about merging for months, with those talks accelerating in the past few weeks.

As...