The CW and Tribune Media have set a five-year affiliation pact for 12 core stations, but the deal calls for WGN-TV Chicago to become an independent station.

The large Chicago station will drop the CW network as part of its parent company’s new affiliation agreement with the CBS-Time Warner joint venture, meaning Windy City residents will have to turn to Fox-owned WPWR-TV Chicago for their fresh episodes of “Arrow,” “The Flash” and “Jane the Virgin” in the fall.

Twelve Tribune-owned stations will continue to broadcast the network, accounting for more than 28 million households, or more than 25% of the U.S.

The stations extending their affiliation agreements with the CW include WPIX-TV in New York, KTLA in Los Angeles, KDAF in Dallas, WDCW in Washington, DC, KIAH in Houston, WSFL-TV in Miami, KWGN-TV in Denver, KPLR-TV in St. Louis, KRCW-TV in Portland, WCCT-TV in Hartford, WGNT in Norfolk and WNOL-TV in New Orleans.

WGN will become an independent station, featuring local news, live sports and syndicated programming during primetime, beginning September 2016.

The pact comes after more than a year of wrangling between the CW and Tribune.

The previous deal, signed in 2006 at the inception of CW, was set to expire in September. Affiliation renewals are usually concluded months if not years in advance of expiration because of the lead time it takes to switch to a new station in a market if a deal can’t be reached.

Tribune and CW had been at odds about the financial terms of the deal, specifically the amount of reverse compensation that CW sought from Tribune stations in exchange for carrying its primetime programming.

CW was known to have been looking at contingency plans for other affiliates in affected markets if the Tribune deal didn’t come to pass. Tribune Media CEO Peter Liguori, the former head of Fox and FX, had been critical of CW’s programming strategy and pushed for a “seat at the table” in the network’s management. But that was before CW began to gain more traction with its superhero dramas “The Flash” and “Arrow.”

Both sides had incentive to make a deal work. Tribune’s decision to carve out WGN-TV Chicago out of the deal came as a surprise. But CW had a ready taker in Fox-owned WPWR, which was once an affiliate of CW predecessor UPN.

CW’s ratings momentum would surely have taken a hit if had been forced to rush station switches in multiple major markets. Tribune Media has been pounding the pavement for buyers or strategic partners for its TV stations, WGN America cabler and audience data businesses. Losing the weeknight primetime strategy for 13 of its biggest revenue-generating stations on short notice would not have been an attractive sell to potential partners.

CW has also been in talks with Netflix on renewing the output deal for its series that expired last year, which made most of its shows available a season after premiere on the network. CW also has a deal with Hulu to make a rolling five episodes available for streaming the day after premiere.

Tribune Broadcasting was also the charter station group for the CW’s predecessor, the WB Network.