I had the same problem with this device I designed in to a product. DO NOT DO THIS, you risk blowing up the batteries. You can not use a P-channel MOSFET, it will conduct the opposite way and start charging the battery from the supply. This is very dangerous!!
The device goes into shutdown mode...