Fox was ready and willing to make a deal with Conan O’Brien.

The network knew O’Brien repped its best chance to establish a latenight beachhead. Per its deal with affiliates, the network was allowed to take back the 11 p.m. timeslot once it had a late night talker ready to go.

The year was 2004.

But Fox ultimately didn’t get a chance to woo O’Brien back then. Instead, NBC convinced the “Late Night with Conan O’Brien” host to stick around for five more years — with the promise that he’d take over “The Tonight Show” in 2009.

NBC’s decision in January to move Jay Leno back to the 11:35 p.m. slot sent O’Brien packing — and most assumed that his bags would be unloaded at Fox.

But with Fox’s inability to make a deal work with O’Brien, who’s now destined for TBS, the network appears to have blown its last chance for a late night franchise. The reason had less to do with Fox’s desire for O’Brien — but instead a critical decision by Fox and its stations made it nearly impossible for the network to clear a latenight timeslot.

Unfortunately for Fox Entertainment execs like chairman Peter Rice and president Kevin Reilly, both of whom had high hopes that they might land O’Brien this time around, a lot had changed since 2004.

The key difference came down to a clause that no longer existed in Fox’s arrangement with its affiliates.

When Fox abandoned its weekday afternoon Fox Kids Network block in 2001, the network retained the right to take back and program those two hours again — as long as it informed affiliates six months ahead of time.

It’s believed that Fox held a similar deal with affils for late night, or, at the very least, that the net had the ability to trade its right to take back afternoons in exchange for an 11 p.m. show. Under such a deal, Fox could have easily cleared O’Brien across the country.

But at some point during the past five years, in renegotiating its affiliate deals (including new digital revenue sharing provisos), Fox gave up the ability to grab a late night slot back.

Such a concession didn’t cause much of a ripple, as there was no indication that a late night show was on the horizon at Fox — which last programmed the daypart with 1993’s disastrous “Chevy Chase Show.”

What’s more, programs like Fox’s “Talkshow with Spike Feresten” and FX’s “Orlando Jones Show,” once considered potential latenight plays for Fox, went nowhere.

With no such franchise in the offing, Fox’s owned stations and affiliates gave late-night commitments to off-net syndicated comedies.

Then suddenly in January O’Brien became available. It’s no surprise that Fox came into play as the most logical new home for the host: Not only did the network have no late-night franchise, but it had gone after O’Brien six years before.

Fox sent out plenty of hints that it would be interested in O’Brien, starting with a statement during the height of the January late-night wars. “We’ve always been interested in late night and we’re always looking to bring great new talent to Fox,” a network source said at the time. “While Conan would be a great fit for Fox, he’s still under contract with NBC, so we’ll just see how all of this plays out.”

At the January TV Critics Assn. press tour, Reilly was much more cautious.

“That becomes a very sensitive business discussion,” he said. “But with a top piece of talent, that makes it a conversation to have.”

Then reality set in. Some Fox execs, unaware that they no longer had the ability to take back 11 p.m., were optimistic that an O’Brien deal might happen — until they realized an O’Brien show would have to be cleared market-by-market.

Then there was the question of the Fox stations’ sitcom commitments. Fox’s owned-and-operated outlets, for example, were committed to carry “30 Rock” repeats in the 11 p.m. hour on WNYW New York and KTTV Los Angeles, among others.

In losing local ad time, and perhaps facing a penalty for moving off-net fare out of guaranteed slots, Fox-owned stations could have faced losses of as much as $40 million to $50 million, one observer said.

“In addition, there was an enormous reticence on behalf of the affiliates on their ability to monetize it and the losses they were going to incur,” the insider said.

Fox stations also are fairly competitive in late night with their repeats, and might have found it difficult to alter the status quo.

During the first quarter of 2010, Fox outlets averaged a 1.3 rating among adults 18-49 and 3.2 million viewers in the 11 p.m. hour. In comparison, during the month of March, NBC’s “Tonight Show” averaged a 1.3 in the demo and 4.9 million viewers at 11:35, while CBS’ “Late Show” posted a 1.0 rating with 18-49 and 3.7 million viewers.

One insider noted that station managers, who are generally not in O’Brien’s target demo, also weren’t clamoring for the host. That older-skewing group of execs might have worked harder to make room for Jay Leno even though Leno wouldn’t have been a logical fit for Fox.

Over the past three months, Fox execs kept trying to find different ways to stick a square peg in a round hole — and it never fit.

“In my mind, it didn’t make a lot of sense for Fox,” said one rival exec. “From what I understand, the only people at Fox who really wanted to do it were Kevin Reilly and the network people. They were myopically focused on it.”

In the end, the decision was going to come down to one person: News Corp. honcho Rupert Murdoch.

“There was one question that mattered,” one observer said. “Is Rupert Murdoch going to tell (Fox TV stations toppers) Roger Ailes and Jack Abernethy that all of their stations are going to put Conan on at 11, and they’re going to lose a ton of money?”

Murdoch, after all, had shown plenty of willingness in the past to lose money to make a big acquisition (the Wall Street Journal or NFL rights). And if Fox ever wanted to get into the late night game, O’Brien repped the best opportunity. In the long term, he might even have led Fox to No. 1 in the daypart, once the aging Leno and Letterman retired.

With the Fox-owned stations on board, the network would have cleared O’Brien in 40% of the country right off the bat. At least another 20% would have followed, with the remaining 40% a hodgepodge of clearances — still good enough to get an O’Brien yakker off the ground.

But Murdoch ultimately didn’t have a vested interest in the late night game. TBS did, and sealed a deal Friday night to launch an O’Brien show this November.

In the end, Fox — which launched in 1986 with “The Late Show Starring Joan Rivers” — doesn’t appear destined to get back into the late weeknight game.