We define HNN-extensions of Lie algebras and study their properties. I
n particular. a sufficient condition for freeness of subalgebras is ob
tained. We also study differential HNN-extensions of associative rings
. These constructions are used to give short proofs of Malcev's and Sh
irshov's theorems that an associative or Lie algebra of finite or coun
table dimension is embeddable into a two-generator algebra.