Having obtained his final degree, he worked as a tutor in Berlin, where in 1743–44 he became secretary to the Hohenzollern prince Frederick William of Brandenburg-Schwedt. Gleim accompanied his employer in the Second Silesian War and made the acquaintance of Ewald Christian von Kleist, whose devoted friend he became. When the prince was killed during the Prussian siege of Prague, Gleim became secretary to Prince Leopold of Anhalt-Dessau; but he soon gave up his position, not being able to bear the roughness of the "Old Dessauer".