It's been a rough few weeks for Samsung's (OTC:SSNLF) smartphones in China. Just last month the company said it experienced increased competition in the country, which led to more smartphone inventory and fewer sales. A lack of demand for Samsung's 3G phones in the China --- as well as increased competition in Europe -- helped pushed Samsung's operating profit down 24% year over year in the second quarter.   

If that weren't enough, research firm Canalys this week published data showing that for the first time in more than three years Samsung was pushed out of the top smartphone vendor spot in China.

Samsung is losing market share in China because of devices like the Mi 3. Source: Xiaomi.

In the second quarter, Samsung's smartphone sales fell 15% year over year in the country, partly because of the push for more 4G phones, as China Mobile (NYSE:CHL) rolls out its new TD-LTE network. Samsung has previously focused on selling its 3G devices in China because that has been the dominant network, but China Mobile increased its 4G subscribers from 1.3 million in February to 14 million in June. The company expects to have 50 million such subscribers by the end of the year. The switch from 3G to 4G devices caused some channel inventory problems for Samsung, which led to lower shipments.

But the biggest contributor to Samsung's recent fall in China is the rise of Xiaomi. The Chinese company took 14% market share in China in the second quarter, growing by 240% year over year. Canalys said in its report that "In little over a year, Xiaomi has risen from being a niche player to become the leading smart phone vendor in the world's largest market, overtaking Samsung in volume terms in Q2."

Here's how Xiaomi's smartphone sales stack up to Samsung's over the past year:

Source: Canalys.

Xiaomi has grown its smartphone business quickly by offering high-end device at mid-range prices, and by creating a loyal following at the same time. Xiaomi's smartphones feature a modified version of Android that is updated every week with user suggestions, which sets the company apart from Samsung and other competitors.

In addition to its software and high-spec products, the company set aggressive goals last year to grow unit sales, and that is starting to pay off.

In 2013, Xiaomi sold 18.7 million smartphones -- more than doubling sales from the year before. This year, the company expects to ship 40 million phones, but it could be as high as 60 million, according to CEO Lei Jun. Adding up the first two quarters of this year, Xiaomi had already shipped 27 million smartphones. All of that growth eats into Samsung and Apple's market share in China, as 97% of Xiaomi's smartphone sales come from its home country.

Why Samsung should be worried
In the second quarter, China accounted for 37% of worldwide smartphone shipments. Samsung is still the global smartphone leader, holding 26% market share, but its stranglehold is loosening. In the second quarter of 2013, the company held a 32% share, and in the first quarter of this year it had 31%.

To regain its position in China, Samsung will have to focus on 4G LTE devices. The second quarter was a transition period for Samsung in China, as it shifted inventory for the faster networks. As China Mobile -- and eventually China Telecom and China Unicom -- build out their 4G networks, Canalys expects Samsung's sales in the country to tick back up, at least in the current quarter.

The big unknown is whether Xiaomi can continue growing at its current levels. If it does, Samsung and other vendors will have a hard time gaining back lost ground. And as Xiaomi begins expansion into Indonesia, Mexico, Russia, Thailand, and Turkey, Samsung and other smartphone makers may have more to worry about than just their China market share.