An emergency program aimed at easing Italy's grave economic and political problems was hammered out here today, with the powerful Communist party playing a decision-making role for the first time in 30 years.

Although the three months of negotiations failed to bring the Communists into a new national government as they had wished, Communist leader Enrico Berlinguer hailed the accord as "a new fact in Italian politics."

A top political scientist here said that "The Communist party can now legitimately claim that it is on the way to becoming, a government party even if it is still excluded from the Cabinet."

The agreement, which emerged from a final seven-hour session, was later approved with minor reservations by representatives of the ruling Christian Democrats, the Communists and three other parties - the Socialists, Social Democrats and Republicans. The tiny Liberal Party, which also supports the government, helped negotiate the accord but abstained from signing until after internal consultations.

Although the Christian Democrats insist that the accord has no direct political implications, observers here agree than acceptance of a common program represents a significant gain for the Communists.

Berlinguer said that an emergency government including all six of the parties that support the minority government is Communists' goal, but that today's limited agreement created "more favorable and avanced conditions" for his party and would make it easier to deal with pressing economic and political problems.

The new program is expected to prolong the life of Premier Giulio Andreotti's government.

A spokesman for the Christian Democratic Party, which has been the Communists' major adversary since the breakup of a three-party coalition with the Socialists in 1947, expressed "porfound satisfaction" with the agreement.

Since parliamentary elections last year in which the Communists won almost as many votes as the Christian Democrats, the government has depended on the abstention of the Communists and the smaller parties for its survival.

The new program, dealing with a vast range of political, social, economic and educational problems, will have to be worked into legislation over the coming months, but a spokesman for the Andreotti government said provisions on limits on public expenditure and labor costs would enable the government to fulfill the conditions of a letter of intent required by the International Monetary Fund when it granted Italy a $530 million loan earlier this year.

The most important part of the package, said the spokesman, is the agreement with te Communists on greater police powers, including preventive arrests, that will enable police to combat growing terrorism and a continuing wave of kipnapings.

Christian Democratic politicians have admitted that they need left-wing support to pass unpopular measures extending police powers curbing the rising cost of labor and cracking down on tax evasion.

The program, which a ranking Communist who spent 200 hours in the marathon meetings described as "fundamentally progressive," also covers long-delayed prison, judicial, health and educational reforms.

Total agreement was lacking. A long-scheduled project for a police union is to be worked out later in Parliament because of disagreement between the Christian Democrats-Communists over the organization's structure.

The Socialist, Social Democrats, Republicans and Liberals expressed reservations on many points. The Socialists and Social Democrats failed in efforts to include a change of government to dramatize the agreement's political significance.

Procedures regarding the political implementation of the 50-page document have not yet been agreed on, but political insiders say it will be sent to Parliament in some form, giving the Communists their first opportunity since 1947 to vote "yes" on a governmental program.

"We are closer to power today then we have ever been," said Ugo Pecchioli, a member of the COmmunist Party's Politburo.

"This is basically a two-party agreement," a Christian Democratic spokesman said. The Christian Democrats and the Communists interpret differently the accord's political significance but agree on the program's value, and recognize that their interests currently appear to be complementary.

One ranking Communist explained the situation this way:

"They lack a parlimentary majority and need the program to be able to govern effectively, and we need it to prove to our supporters that our present policy of government support is paying off."