Spain has agreed to host a visit here this weekend by Nicaraguan President Daniel Ortega in response to an urgent Nicaraguan request that followed western criticism of his current 12-day tour of the Eastern Bloc.

Senior Spanish officials said Ortega also had appealed to France and Italy to allow brief, but official, stopovers before he returns to Managua at the end of a trip that began April 28 in Moscow. According to informed sources, Ortega is to see French officials in Paris Monday.

Plans for Ortega's visit here -- which is described as unofficial -- were made so hastily, following a weekend telephone call from the Nicaraguan government, that officials said they still were uncertain if he would arrive Friday or Saturday. But he follows close on the heels of President Reagan, who ends a three-day state visit to Spain Wednesday.

Irrespective of whether Ortega's Sandinista government can obtain approval of its policies here, the Sandinistas clearly are seeking general acceptance by Western European democracies -- who often sharply disagree with U.S. policy toward Nicaragua.

The Sandinistas appear anxious for a chance to recoup ground they lost by in the West by Ortega meeting with Soviet leader Mikhail Gorbachev in Moscow on April 29, just five days after the congressional defeat of a White House proposal to fund the anti-Sandinista rebel forces.

Members of Congress, as well as some Western European governments, who opposed the funding have said they felt betrayed by the timing of Ortega's travels.

Although this is the closest that Reagan has come to crossing Ortega's path, Nicaragua has been a recurring theme throughout Reagan's tour of Western Europe. Over the past several weeks, actions taken by the two governments have moved in rapid counterpoint.

As Reagan arrived in West Germany to attend the seven-nation western economic summit, the White House announced the imposition of economic sanctions against Nicaragua.

The four Western European members of the summit group -- Britain, West Germany, Italy and France -- plus Canada, all voiced their disapproval of the sanctions as counterproductive.

But criticism of the White House announcement was tempered to some extent by Ortega's appearances in East Bloc capitals, and a Soviet promise of continued diplomatic and political support for Nicaragua.

That same dichotomy was apparent here in Madrid, where Prime Minister Felipe Gonzalez has long criticized administration policy toward Managua but at the same time has indicated discomfort with antidemocratic Sandinista actions.

Gonzalez is a vice president of the Socialist International, and the head of its Latin American committee. His policy of good relations with the Sandinistas as a means of helping them resolve their differences with the United States is popular here.