This is achieved largely by the government sponsoring the most promising/brilliant students to study in top Western universities and offering them quite competitive pay packages to join the government.
The Indian government's elite corps (IAS) as a contrasting example are also composed of similarly brilliant people (including some of my own classmates), but this is restricted to only the people at the very top of the hierarchy and capability doesn't penetrate deep into bulk of the government, nor is compensation as competitive which promotes corruption.