NEW YORK — The New York Mets owners agreed to pay up to $162 million in a settlement announced Monday with the trustee for Bernard Madoff’s fraud victims, a deal that left open the possibility they might pay much less and caused two principal team owners to emerge smiling from the courthouse.

“Stick with us,” Mets chief executive and co-owner Fred Wilpon said outside court. “Now I guess I can smile…. Maybe I can take a day off.”

The agreement was announced by Judge Jed Rakoff just as a civil trial was due to begin in U.S. District Court in Manhattan to determine if the team’s owners might owe as much as $386 million because they were among those who made significantly more than their original investment in Madoff’s company.

The deal left Wilpon and team President Saul Katz, who together personally promised to pay $29 million, speaking confidently of the team’s future.

Katz said outside the courthouse that the team was on secure financial footing. “Always was,” he said.

The settlement gives the Mets breathing room because it does not require any money to be paid for at least three years. It also creates the possibility that the owners could owe nothing if they can secure $162 million of the $178 million they are seeking in claims of their own against the Madoff estate.

“In a sense, we’re now partners,” David J. Sheehan, the attorney for trustee Irving Picard, said outside court as he described how the Mets owners could benefit from the trustee’s recovery efforts.

He also said the amount the team owners could afford to pay was “one of the many factors” that were considered as the two sides negotiated a deal in talks that gained momentum last week and reached a conclusion Friday.

The formal agreement read aloud by Rakoff included a statement by the trustee “that he has reviewed the evidence and will no longer pursue the willful blindness claim against the defendants.”

The trial was expected to showcase what the trustee said was a conscious decision by the Mets owners to ignore warnings that Madoff was operating a multibillion-dollar fraud over several decades, costing thousands of investors about $20 billion.

Outside court, Wilpon and Katz seemed relieved that they were freed from the accusation. They have always insisted they knew nothing of Madoff’s fraud.

“We are not willfully blind,” Wilpon said. “We acted in good faith.”

Katz called litigation “negative energy.”

“We are very pleased to have this behind us,” he said. “We have done everything in good faith. The settlement itself bears that out.”

Picard originally sought $1 billion from the owners, putting a dark cloud over the team that led to an effort over the past year to raise money through new investors. The club also has slashed payroll as its revenue has suffered with declining attendance and product sales as the team has struggled on the field.

Earlier, Wilpon said he was “very, very pleased for ourselves and our families. This was really a team effort.”

He said he was going to Florida today to resume work at “trying to bring the New York Mets back to prominence.”

Rakoff already had ruled the team’s owners must pay up to $83.3 million in profits they received from Madoff. That amount would now be included in the $162 million.

The way to a settlement may have been cleared weeks ago when Rakoff ruled that Picard could only try to recoup $386 million from the Mets owners.

Former New York Gov. Mario Cuomo, who acted as mediator in the deal, said the settlement allows Picard to focus on another 800 pending lawsuits against those who profited from their investment with Madoff.

He said Picard and the Mets owners “avoided the risks and uncertainty of … a long, bitter and expensive trial.”

As to the financial condition of the Mets, Cuomo said: “As far as I’m concerned, they’re not broke.”

He called the deal “fair and reasonable, as fair and reasonable as it could be.”

“Nobody gets everything they want in a settlement. But both sides helped their causes,” he added.

Dodgers Hall of Fame pitcher Sandy Koufax had been scheduled to testify in the trial about Wilpon’s intentions. Koufax invested in Madoff’s private investment business at Wilpon’s recommendation.