When an action is brought wherein it is claimed that any mortgage as to the plaintiff or person for whose benefit the action is brought is fraudulent or void, or has been paid or discharged, in whole or in part, or the relative priority or the validity of liens is disputed, if such mortgage has been foreclosed by advertisement, and the time for redemption from the foreclosure sale will expire before final judgment in such action, the plaintiff or beneficiary having the right to redeem, for the purpose of saving such right in case the action fails, may deposit with the sheriff before the time of redemption expires the amount for which the mortgaged premises were sold, with interest thereon to the time of deposit, together with a bond to the holder of the sheriff's certificate of sale, in an amount and with sureties to be approved by the sheriff, conditioned to pay all interest that may accrue or be allowed on such deposit if the action fail. The person shall, in writing, notify such sheriff that the person claims the mortgage to be fraudulent or void, or to have been paid or discharged, in whole or in part, as the case may be, and that such action is pending, and direct the sheriff to retain such money and bond until final judgment. In case such action fails, such deposit shall operate as a redemption of the premises from such foreclosure sale, and entitle the plaintiff to a certificate thereof. Such foreclosure, deposit, bond, and notice shall be brought to the attention of the court by supplemental complaint in the action, and the judgment shall determine the validity of the foreclosure sale, and the rights of the parties to the moneys and bond so deposited, which shall be paid and delivered by the sheriff as directed by such judgment upon delivery to the sheriff of a certified copy thereof. The remedy herein provided shall be in addition to other remedies now existing.