* Shanghai Composite Index closes up 52.9 pct in 2014
* Best annual performance by major stock market this year
* Welcome respite from otherwise grim economic data
* Hong Kong shares close up 1.3 pct for year (Updates with market closing levels)
By Pete Sweeney
SHANGHAI, Dec 31 (Reuters) - China stocks climbed to near 5-year highs on the last trading day of the year, as mainland markets ended the year up more than 50 percent - the best annual performance by a major global stock market in 2014 after years spent in the basement.
"This year was a bit unexpected," said Tian Weidong, chief director of research department at Kaiyuan Securities in Xi'an.
"I think it took most people by surprise as they didn't realise this sort of market was possible."
The CSI300 index of the largest listed companies in Shanghai and Shenzhen rose 2.2 percent, to 3,533.71, to end up 51.7 percent for the year.
The Shanghai Composite Index gained 2.2 percent, to 3,234.68 points, up 52.9 percent year to date. The last time both indexes were at these levels was January 2010.
The rise is good news for Beijing, as it has successfully convinced many Chinese investors to stop speculating on real estate and diversify into shares in Chinese companies.
And it offers a welcome distraction from an otherwise grim economic performance.
China looks set to post its slowest economic growth rate in decades, but the leadership can console themselves that its stock market, at least, was a world-beater, posting more than five times the annual rise of the Dow Jones Industrial Average .
But the SSEC index is still at roughly half the level compared with where it was prior to the global financial crisis, nor has it recovered to the peak hit during its last rally in 2009, a stimulus-fed frenzy that ended in a savage crash.
Thus the current rally's sustainability is also in question, given that it too has been strongly inspired by policy changes.
The market was bolstered by optimism over monetary easing earlier in the year and rallied strongly after interest rates were cut in late November.
Mainland analysts are calling for another bull year in 2015, but that must be balanced against predictions that the Chinese economy is predicted to slow further, damaging earnings at some of the very blue chip banks that have led the rally.
Technical indicators also show the market is overbought, leaving it vulnerable to a correction in the near term.
In fact, a Reuters poll of Chinese fund managers showed them reducing their equity allocation in the next three months.
The Hang Seng index added 0.4 percent, to close at 23,605.04 points in a shortened trading day, up 1.3 for the year, the widest performance disconnect versus mainland markets since 2007.
The contradiction is highlighted in the index measuring price differences between dual-listed companies in Shanghai and Hong Kong, which stood at 127.76, indicating Shanghai shares are pricing at a major premium.
That difference was supposed to be erased by the launch of the Shanghai-Hong Kong Stock Connect, but the connector has seen extremely weak take-up by both foreign and Chinese investors.
Editing by Jacqueline Wong