Hours before their trial was set to begin yesterday in U.S. District Court in New York, Major League Baseball and ESPN settled their differences and agreed to a new six-year, $800 million contract.

Both sides said they got what they wanted from the settlement. For Major League Baseball, the new contract is worth more than 3 1/2 times the previous three-year, $117 million contract. And ESPN got its wish to be able to continue to show NFL games on Sunday nights.

For at least the first two years of the contract, ESPN's Sunday night baseball telecasts will stop once football season begins. But for each game affected, the network will show two in its place--a Friday night game on ESPN and a Sunday night game on ESPN2 earlier in the season.

"As the process unfolded, it became obvious that this partnership that was under significant strain, was something that was, frankly, beneficial to both sides," Commissioner Bud Selig said.

"That's the thing that moved us forward, and I'm sure it is the same for ESPN.

"It's a good deal for baseball."

Without the deal, ESPN, which lost its rights to NASCAR last month and failed in its bid to secure the NCAA men's basketball tournament, would have been left with little major sports programming in the summer.

The all-sports cable network has been televising baseball games for 10 years, and now has an additional 18 games and the rights to show at least 44 games on ESPN2, plus studio programming for its "SportsCenter" and "Baseball Tonight" telecasts and radio and Internet rights.

"ESPN believes this is a very good deal with plenty of value for us, given the scope of it," ESPN President George Bodenheimer said.

"I certainly didn't feel any pressure [to secure summertime programming].

"All along, baseball was our number one priority."

The agreement apparently was reached Sunday morning, but an announcement was withheld until today so that baseball's owners could be reached.

"ESPN is a great marketing vehicle for baseball," Major League Baseball spokesman Rich Levin said.

"Both sides knew they had to put the dispute behind them and move on together."

The conflict stemmed from ESPN's decision to shift three Sunday night baseball games in September 1998 to ESPN2--which has about 11 million fewer subscribers--to make room for its new $600 million Sunday night NFL package.

In doing so, ESPN cited a clause in its contract giving it the right to move games for events of "significant viewer interest," arguing that the NFL, with average ratings of more than four times that of Major League Baseball, constituted such an event.

Baseball, which previously had granted ESPN permission to shift Sunday night games to accommodate NHL playoffs and the College World Series, among other events, pulled those games off ESPN rather than allow them to be shifted to ESPN2.

In April, baseball announced it would terminate its contract with ESPN following the 1999 season.

"Obviously, I was upset about it, and I didn't hide it from anybody," Selig said.

ESPN filed suit in May in an attempt to force baseball to honor its contract, and baseball filed a countersuit for breach of contract.

ESPN claimed baseball's countersuit was a thinly veiled attempt to renegotiate a new contract. The previous contract was negotiated when baseball was still reeling from the 1994 players strike and was considered below value in 1999.

The new deal is more than what baseball originally asked as compensation for moving the September games to ESPN2.

"It is more important what you get than what you pay," Bodenheimer said.