During the 9th-10th centuries, the dynasty of the Samanids came to the scene of ruling due to which science and education began to develop again. In 995-997, the ruling dynasty of the Karakhanids, who re-established an independent state on the borders of the Eastern territories of the Turkish people, began invasions onto the territory of Khoresm. The Emir of Urgench Ma’mun invaded the city of Kot and after this invasion, the ruling dynasty of the Afrighis was liquidated at all. Gradually the ruling dynasty of the Karakhanids occupied the whole Maveraunnahr and with the consent of the Arabic leaders, they made all the territories on the light bank of the Amudarya their own property. During the years of 997-1017, the ruling power slipped from the hands of Ma’mun I and came into the hands of his son Ma’mun II. Ma’mun II moved I he capital of the country from Kot to Urgench. Being a man of high taste in education and science, he paid great attention to the development of science and education and organized the well-known “Academy of Ma’mun”. The leading scholars and scientists from different countries were invited to the Academy of Ma’mun and they were provided with good conditions to work and teach the youngsters. Beruni was one of the leaders of these scholars and teachers. A good company of scientists took refuge around him. Those years were the years of development of science and enlightenment. It is a great pity that in 1017-1018, Khoresm was again under destruction of the society. The contradictions between the Karakhanids in Maveraunnahr and Mahmud Ghaznavids in Khoresm and Afghanistan (998-1030) were the main reasons of destruction of the smoothly established system of education and enlightenment in the country.
Up to the end of his life, Beruni had to serve the ruling class of the Ghaznavids. According to the writings of a doctor and scribe Ghazanfar at-Tabrizi, Abu Rayhan Beruni died on December 13, 1048 in the city of Ghazni. This scribe copied the last book written by Beruni “Saydana”. A historian and scientist Abu Abdullah Shahabiddin Yaqub (Yaqut) ibn Abdullah ar-Rumi Hamavi (1179-1229), who wrote the biography of Abu Rayhan Beruni, states that Beruni was about eighty years old when he died. He stresses that the year of his death was 1051-1052.
Beruni received his earliest education from his tutor, a famous scholar Abu Nasr ibn Iraq Mansur ibn Ali (died in 1036). Beruni reminded his teacher’s name in his works with great respect and honour. In his turn, ibn Iraq mentioned his student Beruni’s name with respect and appreciation and devoted his 12 books on astronomy, geometry and mathematics to the name of his student and great follower al-Beruni. Ibn Iraq acquainted Beruni with the geometry of Euclid and astronomic teachings of Ptolemy. In his writings, ibn Iraq stressed the uncommon and rare ability of his student Beruni and stated that young Beruni carried independent experiments on astronomy (994-995) and invented a special device for his scientific observations.
After the invasion of the city of Kot by Ma’mun I in 995-997, the dynasty of Afrighis was liquidated as a result of which Beruni’s life, who was in the service of the overturned Emir, was in danger and at the age of 22 he had to leave Khoresm. First he came to the city of Jurjan situated on the southeastern shores of the Caspian Sea and lived there as a stranger. Then he came to the city of Ray in Iran and lived there veiy poorly under hard conditions. Even in the scientific debates, the rich scholars discriminated him and laughed at his poor life. Beruni remembers in the following lines one of the episodes of his hard conditions of life: “In the city of Ray a “scholar entered into the debate with me on the problems of astronomy. Though his knowledge in astronomy was rather low in comparison with mine, he smiled crookedly on me and tried to belittle me and even insulted me. In reality there was poverty between us which could turn the appreciation into humiliation and pride into guilt because at that time I was under very difficult financial and social conditions”.
In Ray Beruni stayed at the house of his friend who was a tradesman. As soon as the political conditions in Central Asia became stable, Beruni came from Ray to Jurjan and began to study at the school of his second teacher — a doctor, astronomer and philosopher Abu Sahl Isa ibn Yahya al-Masihi al-Jurjani (died in 1010).
During the years of 928-1012, Khoresm and the territories on the shores of the Caspian Sea were under the reign of Qabus ibn Vashmgir, a representative of the dynasty of Ziyaris. This ruler offered Beruni the position of a vizier but the scholar kindly refused the offer and decided to be engaged in the scientific researches. In the year of 1000, Beruni completed his world-famous scientific work titled as “Asar al-Baqiya” (Memorials Left by the Ancient People) and devoted it to the ruler Qabus ibn Vashmgir (died in 1012) who was famous with the title “Shams al-Maaliy” (The Sun of High Status). Among the rulers, he was a just ruler and was very keen on the science and enlightenment. As Beruni writes: “God created him as a just ruler, a great defender of the God’s religion and his people, a defender of the people’s properties, and people were thankful for him”. It should be noted that the ruler was a follower of the Shiite order. When Beruni lived in the royal court, he used to behave as if he had been the follower of the Shiite teachings but, in reality,he remained tolerant to all teachings and orders of Islam.