(Adds share price, minister comment)

DUBAI/MADRID, Sept 7 (Reuters) - Jose Maria Alvarez-Pallete, chairman and chief executive of debt laden Spanish telephone and internet service company Telefonica, got an unexpected call this week when he was in Silicon Valley to meet companies and investors in America's tech capital.

He learned Saudi Arabia's largest telecoms operator, STC Group, aimed to be Telefonica's biggest shareholder, with an interest of 9.9%. Within hours of Tuesday's call, Alvarez-Pallete was en route to Riyadh, according to people with knowledge of the situation.

STC had spent months building its 2.1 billion-euro ($2.25 billion) stake, said the people, requesting anonymity because of the sensitivity of the matter. The move is a vote of confidence in Telefonica, burdened by billions of dollars in debt while STC gains expertise to modernize Saudi telecoms infrastructure.

But some in Spain worry the deal could give Saudi Arabia too much sway over the country's telecom and internet infrastructure.

STC is 64% owned by Saudi Arabia's Public Investment Fund (PIF), the main engine of Crown Prince Mohammed bin Salman's Vision 2030 effort to build stakes in a variety of global companies and wean the Saudi economy off its dependence on the oil that made it one of the world's richest nations.

STC hopes the ties with Telefonica will help it develop digital cities in Saudi Arabia, importing technological know-how from countries like Spain, according to a person who had advised the company. For Telefonica, whose market value has sunk to a third of its level eight years ago, the investment offers long-suffering shareholders some respite.

As Telefonica's rivals slashed prices to attract internet users, the Spanish company also borrowed to invest in new mobile and internet networks. Exacerbating the problems, Telefonica has expanded in Latin America, where flagging local currencies, tighter regulation and competition sapped profit in the last decade.

"This provides a much needed boost for Telefonica given the huge investment to rollout fibre broadband 5G in key core markets," said an analyst at PP Foresight.

The new investor "brings confidence and value," Telefonica's main trade union UGT conceded on Thursday, but it worried about growing influence of sovereign funds from theocracies.

Telefonica does not view STC as an aggressive investor that will seek management changes, according to a person with knowledge of the management's thinking.

But the secrecy with which STC built its stake did catch some observers off guard, the person said.

Speculation about a major new shareholder at Telefonica had been mounting. Last year, Telefonica management twice met with other companies and funds in the Middle East, said the people familiar with the matter.

Telefonica said it was informed Tuesday about STC'S investment, after the companies had become more acquainted in recent months. In February, they sealed a strategic partnership to work in fields such as cybersecurity and the metaverse.

By May, STC had hired advisers, including investment bank Morgan Stanley and law firm Linklaters, and started buying Telefonica shares on the market, said two other sources with knowledge of the move.

When the stake neared 3%, STC paused stock purchases to avoid having to make an official market disclosure, one of the people said. STC sought to keep the stake under wraps until it could buy at least 9.9% of Telefonica, the person said.

On Tuesday, STC hit that target, after acquiring an additional 2% stake from undisclosed investors, one of the people said. The balance, 5%, consists of derivatives arranged by Morgan Stanley, and is pending regulatory approval by the Spanish government, they said.

Central to the deal is STC's chief investment officer, Motaz Al Angari, formerly a banker at Morgan Stanley, one person with knowledge of the situation said. STC confirmed his involvement. While at the bank, Al Angari advised on giant Saudi Aramco's record public listing.

Officials for STC declined to comment further. Morgan Stanley and Linklaters declined to comment. Telefonica said: "Our management, strategy and investment teams travel regularly to meet with potential investors, not only in the Middle East, but all over the world."

In a bid to pare debt, Telefonica has sold swathes of telecoms infrastructure, and is set to present a new strategic plan on Nov. 8 with a focus on growing free cash flow, which its CEO has said could reach 4 billion euros this year.

STC has a cash pile of 22.4 billion riyals ($6 billion) that has been underutilised for many years, equity analysts at EFG Hermes said in a note to clients, so the deal should also be good for the Saudi company. However they warned "unsuccessful deals" by STC in the past may worry some.

Since the news on Tuesday, Telefonica shares gained 2.4% while STC fell 1.1%.

Middle Eastern investors have been taking stakes in Spanish companies for some time. The United Arab Emirates' Mubadala sovereign wealth fund owns stakes in oil company Cepsa and gas pipeline operator Enagas, while Qatar's QIA is a shareholder in Iberdrola.

It is a delicate issue in Spain. STC contacted the Spanish government on Tuesday to let them know about the stake and that they did not want to take control, Spain's acting Economy Minister Nadia Calvino said.

"We will apply all the means at our disposal in the interests of defending our strategic interests," she told reporters.

The deal comes at an opportune moment for Saudi Arabia, which soon hosts its annual financial conference attended by the world's top bankers and billionaires, dubbed 'Davos in the Desert'.

"They want their local champions to become global players," said a Gulf banker. "With time they will become as important as a Vodafone or Telefonica itself."

($1 = 0.9348 euros) (Additional reporting by Inti Landauro, Tomas Cobos in Madrid and Amy-Jo Crowley and Pablo Mayo in London; Writing By John O'Donnell and Anousha Sakoui; Editing by Elisa Martinuzzi, David Gregorio and Ros Russell)