A plan for armed Libyan pilgrims to take over the Grand Mosque in Mecca by force almost certainly was incited by Libyan leader Muammar Qaddafi, in the opinion of diplomatic sources here.

In a speech Saturday marking his 15th year of rule, Qaddafi said he had first learned about the plan after receiving urgent messages that morning from King Fahd of Saudi Arabia, King Hassan II of Morocco and Syrian authorities. He appealed to the Libyan pilgrims to call it off and cooperate with Saudi authorities to assure a peaceful end to the month-long pilgrimage season.

Sources here, however, said Qaddafi deliberately incited the pilgrims to take some such action in a speech he gave to a special "people's congress" formed by them just before leaving for Mecca.

They said they did not know whether he had specifically proposed the takeover of the mosque then or simply exhorted them to use the pilgrimage as an occasion to spread his own revolutionary ideas and set up "people's congresses" there. People's congresses, in the governing system developed by Qaddafi, are self-governing assemblies, set up by Libyans both here and abroad.

But the sources said it was inconceivable the Libyan pilgrims could have carried out on their own initiative a political act so inflammatory to Saudi Arabia and the whole Islamic world as the seizure of Islam's holiest shrine without Qaddafi's express approval.

They point to the Libyan attempt to infiltrate arms into Saudi Arabia at the same time and the presence among the pilgrims of "diplomats" and members of the "revolutionary committees" under his direct command as additional evidence of Qaddafi's involvement in planning the takeover.

"There is no doubt Qaddafi gave the order," said one diplomat.

In Beirut, an anonymous caller claiming to speak for Islamic Jihad, a militant Moslem group, said it would strike a "deadly blow" against the Saudi monarchy in Mecca, Reuter reported. The caller told a foreign news agency that Saudi Arabia's withdrawal of its diplomats from Beirut last week after the sacking of its consulate general by Shiite Moslem gunmen would not spare it from further actions.

In Riyadh, the state-run Saudi radio said earlier that the government had withdrawn its diplomats from Beirut "to prevent embassy staff from being killed, since they had been threatened."

Sources here said the Libyan plan apparently was to infiltrate arms for as many as 800 Libyans who were to act as the spearhead of the operation, which would have been disguised as the setting up of a Libyan-style people's congress inside the mosque.

The whole plan was apparently blown when Saudi airport security officials found arms on some of the pilgrims who arrived aboard two Libyan planes Aug. 18. They then became suspicious about the contents of about 20 boxes the pilgrims were trying to bring into the country with them.

Had the seizure of the Grand Mosque been carried out, it might have provoked a major political crisis for Fahd and the Saudi monarchy and ended in a bloody confrontation like the one between Saudi forces and several hundred Islamic extremists who took refuge in the mosque in l979.

The plan raises serious questions about the intent of Qaddafi's present overtures to the Arab world's most conservative rulers, including a new union with Morocco and a year-long effort to improve Libya's relations with Fahd.

Why Qaddafi decided to mention the pilgrims' plan in his Sept. 1 speech is not known, but he appeared to be presenting himself then as the reasonable statesman anxious to help the Saudi authorities.

By that time it was apparent that the Saudis and others already knew something was afoot and had taken action to prevent it. In addition, in the view of observers here, Qaddafi presumably came under strong pressure from Fahd, Hassan and one of his few close Arab allies, President Hafez Assad of Syria.

According to accounts here, a number of Libyans aboard the two planes that arrived in Saudi Arabia on Aug. 18 carried diplomatic passports and refused to allow Saudi customs inspection of the 20 boxes, claiming diplomatic immunity.

The Saudis then refused to allow the Libyans to enter and the plane, with the boxes, returned to Libya.

At about the same time, two Libyan ferries, the Granada and Toledo, arrived, also filled with pilgrims. The Saudis again insisted on searching the pilgrims and ships but the Libyans once more refused and were denied entry.

Many of the people aboard the two planes and ships are suspected of being members of Libyan revolutionary committees sent to lead the seizure of the Grand Mosque.

The committees are the backbone of Qaddafi's political system based on people's congresses. Since a rebel attack May 8 on his headquarters at the Aziziya Barracks in Tripoli, they have taken on enormous power as the regime's main security force as well. Their members also operate abroad on such assignments as attacking Qaddafi's political enemies.

Like Iran's Ayatollah Ruhollah Khomeini, Qaddafi is known to believe that the annual pilgrimage -- a sacred duty for all Moslems -- should not be just a religious event but should be the occasion for political demonstrations.

For the last five years, Saudi police have clashed with Shiite Moslem pilgrims coming from Iran and holding pro-Khomeini rallies in Mecca.

Until recently, Qaddafi was as vehement in his denunciations of the Saudi monarchy and its close ties with the United States as were Khomeini and other Iranian religious leaders. He has often spoken of the need to "liberate" the kingdom and the holy places from all American influence.

In his speech Sept. 1, Qaddafi said he had recently sent letters to all Arab kings and presidents warning that Zionists "under the orders of America" were preparing "to take over Saudi Arabia's oil despite its friendship with America."

In the view of observers here, this could have set the stage for his presenting the takeover of the mosque as part of his efforts to "rescue" Saudi Arabia and Islam's holiest shrine from Israel and the United States.