Farmers and seafarers are squared off in a major confrontation, and a reluctant, uneasy Congress, torn between two of the country's most persuasive special interests, is being asked to be referee.

The fight involves the federal cargo preference law that has been controversial since its passage in 1954. It requires that half of cargoes generated by the government move on U.S. flag vessels, even if using foreign ships is less expensive.

Controversy flared again this year when a federal judge ruled, in a suit brought by the maritime industry, that cargo preference applied to a government blended-credit program intended to move surplus U.S. grain into export markets at attractive prices.

Rather than provide the estimated $40 million or more that would be required to move the grain on U.S. flag vessels as required by the law, the administration suspended the $500 million sales program.

At a time when U.S. export income continues on a four-year downhill slide, the suspension banded farm groups in an unusual show of unity and presaged their set-to with the maritime industry.

Another piquant side to the fight is the apparent dilemma facing several lawmakers with both farming and maritime interests. Washington, Oregon, California, the Gulf states and some eastern-seaboard states all fit into that category.

The Agriculture Department supported several bills introduced by farm-state legislators to exempt the department's commercial-export activities from the cargo preference act. Food for Peace shipments, however, would continue to move under terms of cargo preference.

Although the Senate Agriculture Committee has approved one such bill, the Senate Commerce, Science and Transportation Committee, which shares jurisdiction, reportedly is going in the opposite direction. Its chairman, Sen. Ted Stevens (R-Alaska), is a longtime supporter of undiluted cargo preference.

Now, with the USDA about to announce details of a new farm-export subsidy program, agricultural interests have expressed fear that the maritime lobby will try to have cargo preference applied to all of these subsidized sales. That could torpedo the program by increasing its cost.

"We have agricultural interests united more on this than any other issue in recent years," said Daniel G. Amstutz, undersecretary of agriculture for international affairs and commodity programs. "We hope the legislation will procede . . . , but it's very close, according to those who are counting votes."

Some farm-state legislators, concerned about the political muscle of the maritime industry on Capitol Hill, are seeking a compromise that would avoid actual throwing of punches. "We don't want a bloodbath," one Senate aide said.

"I'm aware of the dilemma," said Sen. Thad Cochran (R-Miss.), who represents a major shipbuilding and farm state.

Cochran said that he, like other colleagues caught between "legitimate competing interests," hoped for a compromise to keep both sides happy. He voted on the farmers' side when the Agriculture Committee passed its cargo bill.

A spokesman for the Transportation Institute, which represents part of the maritime industry, said that compromise was possible. He added, "Our industry still believes the law is clear as to how it is written . . . but we're willing to sit down and talk. There would be room for compromise."

Paul Green, the Millers Federation representative who heads a coalition of 93 agriculture-related organizations opposing the cargo-preference blanket, said the dispute goes well beyond the blended-credit program.

"It is an issue of all commercial sales by the government. This court decision destroys the program, and we can't design a 1985 farm bill with more export incentives unless it is changed," he said. "It's a heavy battle. I've described this as a contest between our wits and their money.

"Several of our best friends in agriculture who are not near the water got campaign money from them in 1984," Green said. "We've made it clear that farmers and agriculture will watch them closely and that they will be expected to vote the interest of our sector. Some members are not excited about having this cargo legislation come up for a vote."

Although three maritime-union political action committees contributed $2.4 million to congressional candidates last year, the Transportation Institute spokesman played down the money's impact on the cargo-preference battle.

"It's not an issue," he said. "Most members vote on the merits."

Rep. Glenn English (D-Okla.), sponsor of a bill that would exempt the blended-credit program from cargo preference, said resolution of the issue is vital to the outcome of farm-bill deliberations, with various proposals to expand farm exports with government-assisted programs pending.

"The issue is very important to Oklahoma and more important in light of the farm bill," English said. "The entire thrust of what we want to do in the export area is in danger because of cargo preference. It will go to the heart of whether American agriculture is going to get back into the export business in a major way.

"There is strong opposition in the maritime industry, but we're trying to see if we can reach a compromise," he added. "The court ruling has become a tremendous threat to what many of us see as a chance for export improvements in a new farm bill."