The European Community resolved a bitter funding dispute involving Greece today, as the price of Athens lifting its opposition to the planned enlargement next year of the 10-nation body to include Spain and Portugal.

Leaders of the 10 member countries, working several hours past their scheduled adjournment, reached agreement on a special aid package to compensate France, Italy and Greece for the fierce competition their farmers face from Iberian producers.

The accord means that the community has now cleared away the last internal financial feud that has frustrated recent efforts to invigorate the drive toward greater European unity. Britain's demand for a budget rebate was settled last summer after preoccupying community summits for five years.

The community now intends to focus on changes that would prepare its institutions for the coming enlargement.

On foreign policies, discussed over dinner last night, the 10 heads of state or government expressed "full support" for recent peace initiatives in the Middle East, according to Italian Prime Minister Bettino Craxi, who chaired the summit.

Craxi said some European leaders believed the United States was "adopting maybe too cautious a line" toward the Middle East. He said the community "wished to encourage those working toward an equitable and peaceful solution."

On the Iran-Iraq war, the leaders urged both countries to seek a cease-fire. The community also "strongly criticized the bombing of civilian targets and the use of chemical weapons," Craxi said.

The terms for Spanish and Portuguese entry were sealed at a meeting of community foreign ministers early yesterday, culminating eight years of difficult negotiations. As the price for lifting its veto, Greece had demanded generous new loans and grants.

Under the terms of the agreement, Greece will receive up to $1.5 billion over the next seven years to help its poor farming regions affected by the enlargement. France and Italy will share a similar amount, with Italian farmers getting most of the money.

West German Chancellor Helmut Kohl, whose country will foot most of the extra bill, said, "The next step will be how to advance political integration" of the community. French President Francois Mitterrand said he was "very satisfied" with the outcome and noted that "the last obstacle has been lifted and enlargement has succeeded."

France and West Germany have been eager to embark on initiatives to streamline the community and establish a system of majority rather than unanimous voting so that a 12-member community would not be paralyzed by lack of consensus.

Craxi, whose country holds the presidency until July 1, said the community is now poised to discuss institutional changes at the next summit, in Milan in June, now that its financial dispute with Greece has been resolved.

The Greek minister for community affairs, Theodoros Pangalos, who took over the last-minute bargaining for Prime Minister Andreas Papandreou after he returned to Athens for the swearing in of Greece's new president, said he felt he was "in the lion's den" confronting nine European leaders who were exasperated with Greece's intransigence.

Pangalos said the compromise was not as good as the one Greece had hoped to achieve but that its disappointment was soothed by "the fact that the community's southern flank will be strengthened by this aid program." Pangalos also said Greece was pleased because "other members have now accepted the idea of creating more convergence between rich and poor regions."