The owners and managers of United Press International yesterday signed an agreement over who controls the company, ending a simmering feud that had caused the wire service's chairman to threaten to ask a federal bankruptcy judge to appoint a trustee to manage the company's affairs.

UPI has been operating for four weeks under protection from its creditors under Chapter 11 of the federal bankruptcy code. It lists about $45 million in debts and $20 million in assets.

The agreement was signed at a hearing before federal bankruptcy judge George Francis Bason following an afternoon of negotiations. As in the original version of the agreement, which was announced last week, Luis Nogales will continue as chairman and the owners and managers will work together to find a buyer for UPI. The owners and managers said in a joint statement afterwards that they had "reached agreement on all matters affecting UPI." Nogales, in an interview, said, "I think we've protected everybody's concerns and interests."

"Without this resolution, the future of the company could be in question," Bason said. "I think we are now well on the way to a successful rehabilitation in this case."

The agreement had appeared to be on the verge of collapse earlier this week when UPI owners Douglas Ruhe and William Geissler balked at the written version of terms they had agreed to tentatively last week. The owners felt the agreement gave too much power to Nogales and UPI's other managers, who have argued that they have control over the company because of a pact signed two months ago in which Ruhe and Geissler relinquished their control.

Yesterday, Nogales, apparently frustrated over the delays in finalizing the agreement, said he was considering whether "to ask the judge to affirm this agreement or to appoint a trustee." Appointment of a bankruptcy trustee in such circumstances is often an act of desperation that can hurt a company's reputation and finances.

In a meeting in Bason's chambers yesterday afternoon, the two sides hammered out a mutually acceptable version of the 14-page agreement -- parts of it covered with handwritten revisions. One allows Ruhe and Geissler to sell their stock in Media News Corp., UPI's parent company, but stipulates that any buyer of Media News would be bound to the terms of the agreement.

As in the previous version of the agreement, Ruhe and Geissler agreed to end their efforts to fire Nogales, and to join with management to find a buyer for the company. Previously, the owners and managers had been using separate investment advisers to screen potential buyers; under the agreement, the adviser will work jointly or give way for the appointment of a jointly agreed-upon adviser.

Nogales said yesterday there were "definitely" interested buyers or investors for UPI, and he said it might take about two months to complete a deal.