An earthquake of magnitude 5.9 struck Taiwan, the United States Geological Survey said on Tuesday, and witnesses said it set buildings shaking in the capital Taipei.