Connect your iPhone 3GS to USB and and close the iTunes. Make sure it remains close during jailbreak process.
Step 1
Go to:

click the Apple icon at bottom of the page to download PurpleRa1n. When prompted, save it to your your desktop for quick access.

Step 2
Double click purplera1n archive to extract it. Then double click the extracted application from desktop to launch it.

Step 3
Click the make it Ra1n button.

Step 4
Now your iPhone 3GS will go into Recovery Mode and your Recovery Mode screen will show GeoHot’s picture.
***NOTE: If, instead of the picture above, you get the screen with the cable and iTunes, wait 1 minute. If the screen remains the same, than something did not work and you must repeat the procedure from the beginning.

Step 5
PurpleRa1n will do its job and your iPhone 3GS will reboot.

Step 6
When your iPhone 3GS is back ON, you will see a new icon named Freeze on your SpringBoard.
Tap Freeze to launch it

Step 7
From Freeze, Tap the Install Cydia button

Step 8
Reboot your iPhone after the Cydia Installation is completed.

Step 9
When your iPhone 3GS is back ON, you will find Cydia icon on your SpringBoard. Launch it and let it perform the Update.

Congrats! you have successfully Jailbreak iPhone 3GS.