Libyan leader Muammar Qaddafi, on his first official visit in four years, and Soviet leader Mikhail Gorbachev reached terms today on several economic and military agreements, according to diplomatic sources.

Qaddafi, one of the Soviet Union's biggest military clients and oldest allies in the Middle East, has been given a warm welcome here as Moscow seeks to strengthen a key source of support in the region.

The Soviet Union will supply Libya with two new submarines, new tanks, a new nuclear power center and will enter into a joint venture on railroad and road building, the diplomats said.

An agreement on a friendship treaty, apparently sought by the Soviets, has not been reached yet, they said. Qaddafi will be in Moscow through the weekend and is scheduled to hold a press conference Monday morning.

The Libyan leader met with Gorbachev today and yesterday for talks that the Soviet news agency Tass said were conducted "in an atmosphere of friendship and mutual understanding." The two agreed on a long-term program of economic, trade, scientific and technical cooperation, Tass said.

In a speech at a dinner in Qaddafi's honor tonight, Gorbachev said that the Middle East is "one of the worst bleeding wounds in the present-day world."

Qaddafi, in reply, called the recent Israeli bombing in Tunis "a brigand attack."

The visit by one of the world's most controversial figures comes at a time when the Middle East is even more volatile than usual.

The recent spate of hijackings and kidnapings -- including, for the first time, the abduction of Soviet hostages in Beirut -- has focused attention on the problem of terrorism in the Middle East. Libya long has been accused in the West of supporting terrorist actions.

Western diplomats here say that Qaddafi's unpredictability sometimes embarrasses the Soviets. Moscow is said to be particularly angry because Libya has supplied Iran with Soviet-made ground-to-ground missiles for use against Iraq, another Soviet ally.