Yelp shares rallied nearly 20 percent in the premarket Friday, after it announced it would sell one of its businesses to GrubHub and buy back $200 million worth of shares. Yelp agreed to sell Eat24, an online food-ordering business, to GrubHub, the parent company of Seamless and MenuPages. The $287.5 million all-cash deal will unite Yelp and GrubHub in a partnership that allows Yelp users to order online directly from GrubHub. Lanny Baker, Yelp's chief financial officer, said in a statement that the deal "demonstrates the value we've created over the past two years." Yelp acquired Eat24 for $134 million in 2015. GrubHub shares briefly fell about 7 percent after hours, but quickly pared losses, last more than 1 percent.

Yelp earnings beat, GrubHub in line

Yelp also announced second-quarter earnings on Thursday, handily beating analysts' estimates and turning an unanticipated profit. Yelp reported earnings of 9 cents per share on revenue of $209 million. That's up compared to earnings of 1 cent per share on revenue of $173.4 million in the year-ago period. Analysts polled by Thomson Reuters expected a loss of 3 cents per share on revenues of $205 million. Yelp saw double-digit increases in advertising and transaction revenue, while the number of reviews grew to about 135 million during the quarter. CEO Jeremy Stoppelman highlighted the company's mobile app, which is on 22 percent more devices than a year ago, as part of the driver of Yelp's growth. The company expects the hot streak to continue. It forecast that it would have revenue of $855 million to $865 million for the full year, well above the $856 million midpoint analysts expected. GrubHub also reported quarterly earnings that were in line with estimates on Thursday, and revenue that topped expectations. The company posted earnings of 26 cents per share, excluding items, on revenue of $159 million. Analysts expected earnings of 26 cents per share on revenue of $153 million. GrubHub said that both the number of active diners on the platform and the value of food sold was up 20 percent or more compared with last year.

Consolidation in food ordering and delivery

Food delivery has become an increasingly competitive space, with companies such as Facebook, Uber and Amazon eyeing the market. Within the last two years, delivery app SpoonRocket was acquired, Danny Meyer-backed Umi Kitchen stalled out, citing "the trickiness of making delivery economics work out for everyone involved." Instacart workers have staged public protests about falling tips, as the CEO is openly pinching pennies. And meal-kit company Blue Apron is trading near its 52-week low after going public earlier this summer. Eat24 will add more scale to GrubHub's network, a factor that the company says helps it compete with other giants. GrubHub spokeswoman Sandra Glading told CNBC earlier this year that the company still believes it has "the broadest, best restaurant network in the space." The convenience will also help Yelp compete with similar integrations at rival TripAdvisor and Groupon. "While we've always been open to exploring partnerships that leverage our scale, and drive a positive experience for our diners and our restaurants, we're constantly innovating to evolve the ordering experience; recent examples include integrations such as Amazon Alexa, Apple TV, Apple Watch and TripAdvisor," Glading said in May.

WATCH: Cramer digs into GrubHub's strategy