The US Geological Survey (USGS) said the quake struck at 1.19pm local time.
It struck 26 km east of Yilan and had a depth of 74.6 km.
The tremors were felt as far away as in Hong Kong.
The Hong Kong Observatory, a weather forecasting agency for the Hong Kong government, wrote on Twitter: “The observation has received reports of locally felt earthquakes.”
There were no immediate reports of injuries or damage to the structure.
The Taipei city government has confirmed that the subway is operating normally without any immediate reports of problems.
However, the Twitter account NERV, which posted disaster information and warnings on behalf of Japan, warned of the “possibility of a tsunami”.
The service tweeted: “At 10.00 pm, a magnitude 6.2 earthquake shook Taiwan at a depth of about 100 km.
“Maximum Intensity 3 We will let you know as more detailed information becomes available.”
Shortly afterwards, NERV tweeted: “There was an earthquake near Taiwan around 10 pm.
“If an earthquake happens on the beach, there is a possibility of a tsunami.
“Stay away from rivers, lakes and beaches as a precaution until we have more information.”
Taiwan, a self-governing island that China claims ownership of, is an earthquake hotspot because it is located near the junction of two tectonic plates.
In 1999, a magnitude 7.3 earthquake shook the country, killing more than 2,000 people.
Hundreds of people died after an earthquake in southern Taiwan in 2016, four years ago.
This is a breaking story. To follow more …