It was a cliffhanger ending, but the Writers Guild of America and the studios have reached a new deal that will keep the scripts coming and Hollywood at work.

The threat of the first strike in a decade was averted after a marathon negotiating session that went past the midnight deadline, leaving much of Hollywood staying up late and checking social media, looking for hints as to whether there would be picket lines on Tuesday.

The parties issued a joint statement confirming the three-year agreement.

In a memo to its membership, guild negotiators cited several key concessions, including increased studio contributions to their health plan, and a new definition for short-order TV series that will earn writers more pay for episodes that take longer than 2.4 weeks to produce.

The contract also adds job protections for members on parental leave.

"Did we get everything we wanted? No. Everything we deserve? Certainly not," the WGA memo added.

A crippling writers' strike in 2007 brought scripted production to a screeching halt and dealt a significant blow to California's economy. Still, the latest talks between the studios, represented by the Alliance of Motion Picture and Television Producers, and the WGA came down to the wire. Their existing agreement was set to expire at the end of the day on Monday.

Related: 2007 writers' strike looms large over Hollywood

Writers had been pressing a number of key demands, including the larger contributions to their health care plan.

For the public, the immediate effects of a strike would have been visible first in late-night television, sidelining programs hosted by Jimmy Fallon, Stephen Colbert, Samantha Bee and Jimmy Kimmel, among others.

The WGA cited massive studio profits as justification for the contentious negotiations, pointing to lavish CEO salaries as proof that writers merely deserved their fair share.

In just the last few weeks, for example, it was reported that CBS chief Leslie Moonves received a pay bump that brought his 2016 compensation to $69.6 million. NBC Universal's Steve Burke took home $46.1 million in 2016 and AMC Networks' Josh Sapan enjoyed a hefty $30.5 million last year, which amounts to a 72% raise.

The writers overwhelmingly voted last month to authorize a strike, giving their the leadership the leverage they hoped they would need to secure a more favorable deal. Still, many writers noted that they were voting for a strike with the hope it wouldn't come to that.

Related: What happens to your favorite shows if Hollywood strikes?

The WGA negotiating committee included notable writers like Damon Lindelof ("Lost"), Jonathan Nolan ("Westworld"), Amy Berg ("Leverage") and Beau Willimon ("House of Cards").

WGA MEMBERS: Thank you for your trust, your patience, and your heart. — Amy Berg (@bergopolis) May 2, 2017

Honored to have served on the WGA negotiating comm. The Chairs & Staff were exemplary. TY membership for the solidarity. #WGAunity works. pic.twitter.com/sbUA9MWtUz — Beau Willimon (@BeauWillimon) May 2, 2017

See you at work tomorrow. Thanks for the 96.3%. Couldn't have done it without you. #WGAunity pic.twitter.com/0q2IiQzHoE — Shawn Ryan (@ShawnRyanTV) May 2, 2017

"WGA MEMBERS: Thank you for your trust, your patience, and your heart," Berg tweeted early Tuesday.

The WGA is one of three major talent guilds with which the studios must negotiate. The Directors Guild of America hammered out a separate deal late last year and talks with the Screen Actors Guild are expected to begin later this month.

Although certain aspects of the guild agreements overlap, each has their own individual concerns that can complicate the negotiations.

While the major studios are large enough to weather a strike for a while, there were incentives to avoid it. Among the most pressing are this month's upfront presentations, when TV networks unveil their fall program lineups to advertisers.