BEIJING (Reuters) - China will soon be burning oil and gas piped in through Myanmar, but putting some of its energy security in the hands of a pariah state beset by international sanctions and civil strife could be a risky gamble.

A gas pipeline with annual capacity of 12 billion cubic meters is due to come onstream within the next two years, carrying the fuel from military-ruled Myanmar's rich offshore deposits into southwestern China.

If all goes to plan, China at some point in the near future will start also receiving 12 million metric tons of oil a year via a separate pipeline, about as much as it imported from Sudan last year, its fifth-largest supplier. There is no exact date for its opening yet.

The former Burma is a friend of China, which has stood by the country's ruling generals, selling arms and providing diplomatic cover when needed -- with an eye firmly on Myanmar's natural resources and access to the Indian Ocean.

But the relationship is more a practical partnership than a meeting of minds, despite the parallels between the two authoritarian governments.

Myanmar's military harbors a profound mistrust of its powerful northern neighbor, while China worries instability in Myanmar could spill over into its territory.

Those fears came to the fore last August when fighting between Myanmar's military and the Kokang rebel group pushed thousands of refugees into China. Myanmar's army ended up firing across the border, provoking irritation in Beijing.

"If Beijing thinks that the pipeline in Burma is going to be relatively trouble-free then they ought to rethink," said Maung Zarni, a Myanmar expert at the London School of Economics (LSE) Centre for the Study of Global Governance.

"Even a regime that is currently in a marriage of convenience with them would fire into Chinese territory," he added.

MALACCA STRAIT PROBLEM

China, the world's second-largest oil user, sees the pipelines as a way to get around what in domestic energy strategy circles is known as the "Malacca Strait dilemma."

The fear is that during a conflict, a hostile power could choke off energy supplies that are taken on supertankers through the narrow Strait of Malacca between Malaysia and Indonesia.

Some 80 percent of China's oil imports arrive this way.

The area already has a piracy problem. In 2005, the Joint War Committee of the Lloyd's Market Association added the area to its list of war risk zones.

Bringing energy supplies through Myanmar is a handy way to avoid the Strait, and expands efforts to diversify supply routes with crude and gas pipelines from Central Asia.

"One of the pipelines will be purely for oil, and that oil isn't coming from Burma. It will be offloaded from tankers coming from the Middle East and then piped to Yunnan and on. It's very important," said Ian Storey, a fellow at Singapore's Institute of Southeast Asian Studies.

"One way of looking at the Kokang incident is the Burmese were actually just clearing the border in preparation for that pipeline. So China couldn't be too critical of that incident because it's in their own interests."

But the benefits may be more than offset by two major risks -- the many disparate rebel groups who have fought Myanmar's central government for decades, and popular mistrust at an influx of Chinese migrants and traders into Myanmar.

"Think of a population that is seething with resentment toward the Chinese that borders on hatred," said LSE's Maung Zarni. "An 800-km pipeline is too good a target if the Burmese want to harm Chinese interests."

Already, residents along the pipelines' route have attacked Chinese workers and offices, angry at the seizure of their land and property, said Wong Aung, a spokesman for the Shwe Gas Movement, which is campaigning against the project.

"We can only imagine people's anger at the Chinese," he said by telephone from Thailand. "That kind of social unrest, or attacks, could take place at any time."

Factor in India's jockeying for influence in Myanmar, driven by Delhi's fears that China is surrounding it with pro-Beijing states, and the potential for problems rises further.

"If at any time India feels they have lost Burma to China, you can easily imagine a scenario where India quietly assists disgruntled military units or dissident groups which may become radicalized to target Chinese assets," Maung Zarni said.

But Myanmar is keeping India in the game by offering stakes in the pipeline to two Indian gas companies. State-run Gail India (GAIL.BO: ) will pick up a 4 percent stake and Oil and Natural Gas Corp (ONGC) (ONGC.BO: ) will take another 8-8.5 percent, Indian media reported last month.

PUBLIC RELATIONS DISASTER

The project could become another international public relations disaster for China, coming hot on the heels of the opprobrium Beijing attracted ahead of the 2008 Olympics for its oil investments in Sudan.

Rights groups have repeatedly expressed concern that pipeline construction will bring abuses against local peoples, mainly by Myanmar's army which will be tasked with protecting the project.

Yet desire for the oil and gas is such that the risk of another unhappy round of poor global public relations for China is one Beijing will be happy to take, said David Mathieson, Myanmar researcher for New York-based Human Rights Watch.

"Potentially that pipeline project could really become a touchstone for all the other things China does in Burma, and it could be immensely embarrassing to them," he said.

"(But) I actually don't think that's enough to stop the project. They've wanted that gas for a very long time."