If a taxpayer fails to pay overdue taxes, the IRS has the right to place a lien on the taxpayer's real property. An IRS lien is the federal government's legal claim against the taxpayer's property to secure payment of the tax debt. Upon sale or foreclosure of the home, who gets paid first - the mortgage or the IRS?
The answer depends on the "priority" of the lien. If the IRS files a lien on property that already has an existing mortgage, the mortgage has priority over the IRS lien. Upon sale or foreclosure of the home, the proceeds would first be used to pay the mortgage, and if there is enough left over, the IRS would be paid next. If the IRS files a lien on property that has an existing first and second mortgage, the IRS lien would be third in priority and wouldn't be paid until after the two mortgages are fully repaid.
On the other hand, if the IRS files a lien on property that is owned free and clear of any mortgages, the IRS lien will have priority over any subsequent mortgages that the homeowner obtains. In reality this situation is unlikely to occur since most mortgage lenders would not be willing to provide a loan on property that has a pre-existing tax lien.