A mandarin (; Vietnamese: quan) was a bureaucrat in imperial China, and also in the monarchist days of Vietnam where the system of Imperial examinations and scholar-bureaucrats was adopted under Chinese influence.
The English term comes from the Portuguese mandarim, borrowed from Malay , and ultimately coming from Sanskrit mantrin (Devanagari: मंत्री) (meaning councilor or minister). This usage and etymology among the Portuguese are attested already by Matteo Ricci, who entered the mainland China from the Portuguese Macau in the late 16th century. According to Malaysian Royal Professor Ungku Abdul Aziz, the term had its origin when the Portuguese living in Malacca during the Malacca Sultanate wanted to meet with the higher officials in China, and used the term "menteri", but with an added "n" due to their poor grasp of the language, to refer to higher officials.
The term "Mandarin" is also used to refer to the standard northern spoken variety of Chinese because it was the language used among officials during the Ming and Qing dynasties. It can be thought as the translation of the Chinese name Guanhua ("the language of the officials") for this speech standard, which was current already in the Ming Dynasty.
In the West, the term mandarin is associated with the concept of the scholar-official, who immersed himself in poetry, literature, and Confucian learning in addition to performing civil service duties.
For around 1300 years, from 605 to 1905, mandarins were selected by merit through the extremely rigorous imperial examination.
China has had civil servants since at least the Zhou Dynasty. However most high ranking positions were filled by relatives of the sovereign and the nobility. It was not until the Tang Dynasty when the final form of the mandarin was completed with the replacement of the nine-rank system. The mandarins were the founders and core of the Chinese gentry. The mandarins were replaced with a modern civil service after the fall of the Qing Dynasty.