The European Community's 10 heads of government warned today that a trade war with the United States must be averted or the seven-nation economic summit in Williamsburg, Va., in May could be undermined.

At the end of a two-day summit here, the 10 leaders in a concluding communique that also was critical of both Israel and the Palestine Liberation Organization declared themselves "deeply disturbed by the continued lack of progress" toward peace in the Middle East and called for the urgent withdrawal of all foreign forces from Lebanon as a prelude to resuming negotiations for a comprehensive peace accord.

The communique, denouncing Israeli settlements on the West Bank as a "major and growing obstacle" to peace efforts and insisting that Israel should refrain "from enlarging existing settlements or creating new ones," also urged the PLO to "seize the present opportunity" and endorse the idea of peace negotiations.

With the pall of recession still hanging over much of the world, European leaders want the May economic summit, the first to be hosted by the United States, to concentrate on bolstering a sustained recovery of the international economy and not be sidetracked by the current dispute over agricultural trade subsidies.

Today's communique said that "a genuine dialogue" between the United States and the community over trade in agriculture could be maintained only on the basis of previous agreements with the United States. This was a reference to an earlier U.S. undertaking to accept the Common Agricultural Policy, the community's Europe-wide farm program. Washington has been exerting pressure on the Europeans to restrict their sales of subsidized farm products.

West German Chancellor Helmut Kohl said at a press conference today that the U.S.-European dispute over the subsidies, as both compete to find markets for their grain surpluses, will lead to "hard and tough negotiations, but I hope these will prove to be talks among friends."

European and U.S. officials met last week in Washington to explore a compromise, but achieved little progress. Negotiations to work out an orderly sharing of the markets are expected to resume in April in an effort to reach an agreement before the Williamsburg summit.

"A solution is not going to be easy," British Prime Minister Margaret Thatcher said. "There are only a few markets in the world where you can sell grain surpluses."

"We are particularly anxious not to get into a situation of competitive subsidies with the United States because that would be absolutely ridiculous," she said. A prime cause of the trade pressures faced by American farmers, she suggested, derived "from an unduly strong dollar."

Earlier today, Kohl and French President Francois Mitterrand held a breakfast meeting to heal the wounds of a bitter quarrel over currency values that threatened to disrupt the summit and throw foreign exchange markets into turmoil.

Only hours before the summit began yesterday, European finance ministers patched together a compromise by which the West German mark was upgraded by 5.5 percent and the French franc devalued by 2.5 percent. Paris had fought hard against a third devaluation in 18 months and wanted Bonn to raise the value of the mark even more.

On leaving the morning session with Mitterrand, Kohl admitted that "there were tensions between France and West Germany, but they are now behind us." Later he said that the two capitals would hold a series of ministerial meetings to defuse future disagreements.

At the press conference, Kohl said there were "bound to be stormy periods" between the two allies but that West Germany was prepared "to make sacrifices as a show of solidarity for its European partners."

Kohl told reporters that he expects 1983 to be "the most important year of the postwar era" because of the difficult economic situation and the tensions aroused by the planned deployment of cruise and Pershing II nuclear missiles in Europe this year. For that reason, he continued, it is important to avoid exacerbating trade and security disputes at a time when the western alliance will be severely strained.

Mitterrand, who declined to speak with reporters and left hastily for Paris to restructure his government, was known to have pressed during the summit for tough measures to prevent the United States and Japan from making too many inroads into European markets.

But other participants insisted on calling for a "strengthening of world trade" as part of an integrated policy designed "to bring about a favorable climate of sales possibilities without renewed inflation."

The community's harsh condemnation of Israel's settlements policy and open appeal for PLO participation in the peace process went beyond previous European declarations that have called for the recognition of all states in the region and rights of Palestinian self-determination.

While they acknowledge American primacy in guiding the negotiating track, the Europeans' dependence on Arab oil supplies and commercial interests in the Persian Gulf region have nurtured a more forthright political approach toward the nature of peace in the Middle East.

In today's communique, the European leaders backed President Reagan's peace initiative calling for an association between the West Bank and Jordan and "welcomed the discussions between Jordan and the PLO."

The 10 leaders stressed that they were not launching a new declaration of their own, but merely recognizing "the urgency and the opportunity" now confronting Israel and its Arab neighbors in the quest for a lasting peace, Thatcher said.

"The time is ripe to make progress on the withdrawal of all foreign forces from Lebanon as well as the fundamental Palestinian problem," she said. "We don't want the whole thing to fall between two stools."