The Oirats began to penetrate into the territory of the Kazakh Khanate in the 15th century — that is, when the Kazakh state was formed. Relations were peaceful — there was enough space in the steppe for everyone. Under the Kazakh khan Taukele, the Oirats became an integral part of the Kazakh Khanate:
«Your uncle Tevkel tsarevich tsar was established on the Kazak horde, and his brother Shah-Magmet tsarevich planted on the Kalmaks, and all of them roam around and all of them are united» — wrote from the Kazakh steppe in 1595 to the Kazakh khanzade Oraz-Muhammed under the Moscow sovereign Fyodor I
In the XVII century the situation changed dramatically. The Oirats created their own Dzungar Khanate, and the Kazakh Khanate began to weaken due to internal strife.
Taking advantage of this, in 1643 the first Dzungarian khan Erdeni-baatur at the head of 50 thousand troops invaded Semirechye. But in the gorge of the Orbulak River (Dzungarian Alatau) they were ambushed by 600 Kazakh riflemen under the command of Zhangir Khan in the fortifications in the mountain gorge. The Dzungarian militia came under fire from the Kazakh multuks and scattered. Then 20 thousand Bukhara warriors of tarkhan (owner) of Bukhara Zhalantos-Bahadur struck at the remnants of militia. They finally defeated the militia, but Erdeni-Baatur managed to take away his lat cavalry — the main power of his forces.
In 1681, the Oirats again invaded Kazakh lands and destroyed Sairam in southern Kazakhstan. But that was the end of their successful actions and the Kazakhs were able to fight back relatively easily.
In 1722 , the Manchurian emperor Kansi, an implacable opponent of the Dzungars, died. His successor Aisingyoro Yinzhen was peace-loving and did not continue the long-standing conflict between the Qing Empire and the Dzungar Khanate. This allowed the Dzungars to unleash all their forces to finally settle the issue with the Kazakhs.
In 1723 , the Dzungars invaded the Kazakh lands in seven columns:
A detachment under the command of Galdan-Tseren moved in the direction from Lake Balkhash to the Karatau Mountains; a detachment of Erdeni-Batur, having crossed the Altai Mountains, passed through the valleys of the Koktal River; a detachment of Amursana headed for the Nura River; a fourth headed for the Chilik River; a fifth moved through Priissykkulie; another group passed through the Chui Valley; the last group passed unhindered through the Ili River. They suddenly descended upon the Kazakhs and seized a large part of their territory. The Dzungars captured and plundered Sairam, Turkestan, Tashkent — Wikipedia
In 1724 , the rulers of Samarkand and Khodjent became vassals of the Dzungars. In 1725 , the Dzungars subjugated the Karakalpaks.
The critical situation forced the Kazakhs to unite and forget about tribal conflicts. In 1726 , a congress of many Kazakh clans took place in Ordabasy, where it was decided to jointly fight against the Dzungars. The united Kazakh army was headed by the khan of the Younger Juz Abulkhair.
In 1727 the irreconcilable enemy of Kazakhs Tsevan-Rabdan (an ardent Buddhist) died. Galdan Tseren, loyal to the Kazakhs, became the new khuntaiji (khan).
Galdan-Tseren, (Tseren, 1693? — 1745) — the fifth khuntaiji of Dzungarian khanate with the title Erdeni-Batur-khuntaiji II (1727-1745). A member of the Choros family, the eldest son and successor of the Dzungar khuntaiji Tsevan-Rabdan — Wikipedia
Galdan Tseren saw the conquest of Khalkha (Northern Mongolia) as his main task. He directed all his forces there. In Semirechye, a militia and about 5,000 latents remained against the Kazakhs.
Taking advantage of this Kazakhs for two years — in 1727-1728 waged a guerrilla war against small detachments of Dzungars in the Ulytau mountains. This allowed to cut the communications between Kalmyks and Dzungars (Turgai way), which seriously weakened their forces.
After that, in the winter of 1729-1730, the Kazakhs were able to dislodge the Dzungars from the line of fortresses on the Chu River (the Anrakai Campaign). After that Semirechye easily passed into the hands of the Kazakhs.
But in 1734 the Dzungars, having gathered their forces, again conquered the territories of the Kazakhs of the Elder Juz.
This forced the Kazakhs to consolidate around the khan of the Middle Zhuz Abylai. That in 1740 stops further expansion of the Dzungars, having defeated them in a number of battles.
In 1742, Abylai, who tried to organize resistance to the next invasion of the Dzungarian Khanate on the Ishim River, was defeated and captured. According to legend, he killed a noble noyon, a relative of the khan Galdan-Tseren, in a duel. During his captivity, Abylai learned the Mongolian language and possibly Manchurian; he was a frequent guest of Galdan-Tseren, and became friends with the later legendary yon Amursana — Wikipedia
In 1743 , the Russian embassy of Karl Miller came to the Dzungar headquarters and released all Russian subjects, including Abylai (they did not come specifically for him).
Abylai Khan (Kaz. Abylai Khan; real name Abilmansur (Kaz. Әбілмансұр); 1711, Turkestan — May 23, 1781, Tashkent) was a Kazakh statesman and politician, khan of the entire Kazakh Khanate, recognized by all zhuzes.He was the son of Korkem Uali-sultan, grandson of Abylai Khan Kansher, descendant of Barak Khan (9th tribe) — Wikipedia
In 1745 Galdan Tseren dies and civil war begins in the Dzungarian khanate. On it military actions between Kazakhs and Dzungars practically stop, and in 1759 the Dzungarian Khanate ceases to exist.