Property liens can be Involuntary (I.E. HOA, judgment, mechanic, tax etc.) or Voluntary (mortgage, refinance, home loan etc. ).
Both have to be satisfied/paid in full before title can be conveyed properly. In most cases, Involuntary liens can be negotiated with the creditor for a smaller amount due to the nature of the encumbrance.
First mortgages (AKA senior liens) always take priority over second mortgages (junior liens) in a foreclosure proceeding or auction.
For more information on this subject you can visit https://www.ustitlerecords.com/title-search-resources/ for helpful resources.