Disclosed are compounds of formula (I), (II), (III), and (IV), and pharmaceutically acceptable salts thereof. The compounds are inhibitors of ALK2 kinase. Also provided are pharmaceutical compositions comprising a compound of formula (I), (II), (III), or (IV), or pharmaceutically acceptable salt thereof, and methods involving use of the compounds or pharmaceutically acceptable salts thereof and compositions in the treatment and prevention of various diseases and conditions, such as fibrodysplasia ossificans progressiva.