I'm not sure about 401k specifically, but many retirement plans allow unpenalized withdrawals for first-time home buyers. Also, a house can be considered an investment so other retirement plans allow for such purchases. Obviously, you'll need to discuss this matter with a professional, perhaps...