Assuming that the mortgage predates (was recorded before) the judment liens, then the foreclosure sale wipes out the liens. If the foreclosure sale produces surplus funds (more than is required to pay off the mortgage and pay the costs of the sale), those surplus funds go to pay off the liens (before the former owner gets any surplus), but anything not paid off during the foreclosure process if simply eliminated, because older liens or securty interests, like a purchase money or first mortgage, wipe out later liens when foreclosed upon.