Get your taxes done using TurboTax

Yes.  Buying a new home first does not defeat the exclusion.  You only must meet the 2 year ownership test and the main home for 2 of the past 5 year test (731 or more days in the 5 years before the sale.)

 

However, note that you can't use the exclusion again for 2 years after the previous time you used the exclusion.  So if you wanted to sell your newest home and use the exclusion, you would have to wait 2 years and some number of months, based on the closing date of the previous sale.