At least temporarily. Filing bankruptcy will immediately stop a foreclosure proceeding, however the lender may be able to obtain permission from the bankruptcy court to lift this stay and then proceed with the foreclosure. Regardless, filing bankruptcy may give you enough time to modify your mortgage or arrange for a short sale.
You may also be able to keep your home through certain legal proceeding in a Chapter 13 bankruptcy that will force your creditors to accept a payment plan or even eliminate some of your mortgage debt. Usually, you will need to reach an agreement with the lender and keep making your payments.