It is safe for women to walk alone at night in Istanbul, and there are millions that do without problems. However, some neighborhoods, such as Fatih, Aksaray, Tophane, Tarlibase, and much of the backstreets of Beyoglu have unsavory reputations at night. If you walk alone, make sure you radiate confidence- don't look afraid or like "easy prey." Even if you are lost, try to look like you know what's going on, and ask for directions firmly and confidently. Many women report talking on the phone or carrying it in their hands makes them less of a target as well. If you feel threatened, it's best to react as if you are being harassed; cause a scene, wake people up, etc.
I've found myself feeling safer here than at most US cities. But if possible, go places with friends or get someone to walk you home late at night. It's better to avoid those situations, just like anywhere. And John's right about making a scene to get the attention of others. Also, you can go into an open shop (which there are always a few open to even 3am or later) and that usually deters them. If the person is still persisting, you can communicate to the shopkeeper that you're in trouble--that will really help.