The first Jannisaries were not Christian youths taken into military service, but captured enemies converted to Islam and made to fight for the Sultan. How did the Ottomans ensure their loyalty?

by conbutt

Also, what stopped them from deserting and rejoining their former kingdom or state?

Zooasaurus

Technically they were taken as slaves or ghanimah for the Khan/Sultan under the Pençik system, meaning that the Sultan take one slave out of five slaves captured by ghazi raiders (so their number is quite limited). However, i believe that their training was the factor that made them loyal. Only physically fit, sturdy and young slaves were selected, and they then sent to Turkish farmlands to work in the fields and to learn the Turkish language and culture and convert to Islam for up to eight years. After that, they were taken to Acemi Ocağı in Gallipoli, where their military capability is honed and absolute loyalty to their superior and the Sultan is forged, as they were isolated physically and culturally from everybody except the ruler and their unit.

Sources are from A Military History of the Ottomans and Origins of Janissaries