iPhone 3GS switches off randomly after update to 5.0.1
I tried jailbreaking and installing iOS 4.2, and the issue persisted so I concluded it's a hardware problem. After four months, I finally got the battery replaced, and the service guys told me there was a problem with the old battery's circuit.

The new battery works just fine.