* Santander to buy 8 pct Bank of Shanghai stake from HSBC

* Deal, including cooperation agreement, worth 470 mln eur

* Bucking the trend as big rivals sell out of China

* Santander says eyeing China trade flows with Latam

(Adds details on price, Santander's Chinese ventures)

By Sarah White and Matt Scuffham

MADRID/LONDON, Dec 10 (Reuters) - Santander SAN.MC , Spain's largest bank, is to buy HSBC's HSBA.L 8 percent stake in Bank of Shanghai, just as many international rivals are beginning to sell out of China.

Santander, which already has a consumer finance venture in China as well as a car financing business, said on Tuesday the Bank of Shanghai deal also included a cooperation agreement, taking the value of its investment to 470 million euros ($647.3 million).

Several major U.S. and European banks including Bank of America BAC.N and Switzerland's UBS UBSN.VX have started shedding their Chinese holdings for a variety of regulatory and business reasons.

HSBC, meanwhile, has been selling minority holdings as part of a restructuring since the start of 2011. It has cut 46,000 jobs and sold or closed 52 businesses, including a minority stake in Chinese insurer Ping An.

But Santander said it would help state-controlled Bank of Shanghai, which it said had 98 billion euros of assets and was the second-biggest city-focused commercial and retail bank in the country, with training in areas such as risk management.

It is also planning to develop a joint wholesale banking business, adding to what Santander might be able to offer some of its big corporate clients in Latin America, a key hub that provides around 50 percent of its profits.

"Santander is also developing investment banking activities in China, mainly based on financing the substantial trade flows between the Asian giant and Latin America," the bank said in a statement which listed existing ventures in China.

Asia-focused HSBC said China was still one of its priority markets and Chief Executive Stuart Gulliver has said in recent months that its 19 percent stake in Bank of Communications

601328.SS remained core.

"Our priorities ... will emphasise the growth of our own operations in mainland China and our own partnership with Bank of Communications," Peter Wong, chief executive of HSBC Asia Pacific, said in a statement on Tuesday.

JOINT VENTURE

Gulliver had said in May that HSBC could sell its Bank of Shanghai stake for between $500 million and $600 million. Santander declined to comment on Tuesday on how much it had paid for the 8 percent stake alone.

Santander also has 20 percent of Bank of Beijing's consumer finance subsidiary and earlier this year launched a 50/50 joint venture in car financing with Anhui Jianghuai Automobile (JAC)

600418.SS .

Peers have been selling out of China in part because some struggled to make quick progress with their Chinese joint ventures, and also because they are bulking up capital ahead of more stringent international solvency rules.

Santander's main rival in Spain, BBVA BBVA.MC , recently trimmed its stake in China's CITIC Bank Corp 601998.SS to just under 10 percent, as having stakes in foreign banks will become more expensive over that limit under new capital regulations.

ID:nL3N0I717P

Santander has sold assets elsewhere in recent years, including in Latin America. But it has been in a more acquisitive mode in recent months, even in its home market Spain, which is slowly emerging from a five-year economic slump.

In October it spent 140 million euros on a 51 percent stake in the country's largest consumer finance business, run by department store chain El Corte Ingles.

Santander said it expected its deal with Bank of Shanghai to close in the first half of 2014. It said the transaction would impact its capital to risk-weighted assets ratio by about 0.01 percent.

Bank of Shanghai was reported earlier this year to be planning to list its shares in Hong Kong within the next 12 months, though it was not immediately clear if the Santander deal would influence those plans. ID:nL3N0CW0IW ($1=0.7261 euros)

(Editing by David Holmes)

((paul.e.day@thomsonreuters.com)(+34 91 585 83 08)(Reuters Messaging: paul.e.day.thomsonreuters.com@reuters.net))

Keywords: SANTANDER HSBC/

* HSBC places fair value of $468.2 million on stake as of Sept. 30

* Santander says eyeing China trade flows with Latam

* Bank of Shanghai expected to list shares in HK, Shanghai

By Sarah White and Matt Scuffham

MADRID/LONDON, Dec 11 (Reuters) - Santander SAN.MC , Spain's largest bank, has agreed to buy HSBC's HSBA.L 8 percent stake in Bank of Shanghai, expanding its presence in China at a time when other foreign banks have hit the exit button.

Santander, which already has a consumer finance venture and a car financing business in China, said on Tuesday the deal also included a cooperation agreement with the Chinese bank, taking the value of its investment to 470 million euros ($647.3 million).

The deal is seen helping Bank of Shanghai move a step forward with an expected initial public offering by giving it a secure foreign investment and a valuation. The Chinese lender is seeking an IPO in Shanghai and Hong Kong with a combined value of about $2 billion. ID:nL4N0GS084

Bank of Shanghai officials could not be immediately reached for comment on the deal or the IPO plans.

HSBC had earlier flagged its interest in selling the stake, which it said had a fair value of HK$3.63 billion ($468.18 million) as of Sept. 30. The Asia-focused bank paid $62.6 million for the holding in Dec. 2001.

HSBC has also been selling minority holdings as part of a restructuring since the start of 2011. It has cut 46,000 jobs and sold or closed 52 businesses, including a minority stake in Chinese insurer Ping An.

U.S. and European banks, including Bank of America BAC.N , Goldman Sachs GS.N and UBS UBSN.VX have also sold their stakes in Chinese banks, booking hefty profits from holdings that yielded few strategic advantages. Regulatory and other business reasons also prompted the sales.

Santander, however, is moving in the other direction.

The bank said it would help state-controlled Bank of Shanghai, which it said had 98 billion euros of assets and was the second-biggest city-focused commercial and retail bank in the country, with training in areas such as risk management.

It is also planning to develop a joint wholesale banking business, adding to what Santander might be able to offer some of its big corporate clients in Latin America, a key hub that provides around 50 percent of its profits.

"Santander is also developing investment banking activities in China, mainly based on financing the substantial trade flows between the Asian giant and Latin America," the bank said in a statement which listed existing ventures in China.

Asia-focused HSBC said China was still one of its priority markets and Chief Executive Stuart Gulliver has said in recent months that its 19 percent stake in Bank of Communications

601328.SS remained core.

The transaction is subject to approval from the China Banking Regulatory Commission.

JOINT VENTURE

Gulliver had said in May that HSBC could sell its Bank of Shanghai stake for between $500 million and $600 million. Santander declined to comment on Tuesday on how much it had paid for the 8 percent stake alone.

Santander also has 20 percent of Bank of Beijing's consumer finance subsidiary and earlier this year launched a 50/50 joint venture in car financing with Anhui Jianghuai Automobile (JAC)

600418.SS .

Peers have been selling out of China in part because some struggled to make quick progress with their Chinese joint ventures, and also because they are bulking up capital ahead of more stringent international solvency rules.

Santander's main rival in Spain, BBVA BBVA.MC , recently trimmed its stake in China's CITIC Bank Corp 601998.SS to just under 10 percent, as having stakes in foreign banks will become more expensive over that limit under new capital regulations.

ID:nL3N0I717P

Santander has sold assets elsewhere in recent years, including in Latin America. But it has been in a more acquisitive mode in recent months, even in its home market Spain, which is slowly emerging from a five-year economic slump.

In October it spent 140 million euros on a 51 percent stake in the Spain's largest consumer finance business, run by department store chain El Corte Ingles.

Santander said it expected its deal with Bank of Shanghai to close in the first half of 2014. It said the transaction would impact its capital to risk-weighted assets ratio by about 0.01 percent.

($1=0.7261 euros) ($1 = 7.7535 Hong Kong dollars)

(Additional reporting by Michael Flaherty in HONG KONG; Editing by David Holmes and Miral Fahmy)

((paul.e.day@thomsonreuters.com)(+34 91 585 83 08)(Reuters Messaging: paul.e.day.thomsonreuters.com@reuters.net))

Keywords: SANTANDER HSBC/