A long running thread on the Apple support forums has had a number of iPhone users complain over the months that their iPhone, primarily the 3GS, has been turning off randomly despite the fact that their battery is sufficiently powered. Some users seemed to have experienced this issue even when the battery was loaded by more than 90%.
The initial suspects for the problem was the iOS. Users complained that they started seeing the problem soon after upgrading to one of the several recently released versions. However, as some of them are now beginning to conclude, the issue could be due to a batch of bad batteries that may be causing the problem. Users who have got the batteries on their iPhone replaced have noticed immediate improvement.
If you are one of the affected users, you may approach your nearest Apple Store for a battery replacement. Of course, if you don’t care much about warranties and want to replace the batteries yourself, you can click here and here to purchase replacement batteries for iPhone 3GS and iPhone 4 respectively.