The city was the capital of the Khazars , a semi-nomadic Turkic peoples who adopted Judaism as a state religion , from between the 8th and the 10th centuries , when it was captured and sacked by the rulers of ancient Russia .