A 6.2 magnitude earthquake struck the Indonesian island of Sumatra, killing at least two people.

According to the national civil protection agency, 20 other people were injured.

The earthquake occurred on Friday morning in the north of the island, about 70 kilometers from the city of Bukittinggi, at a depth of about twelve kilometers, according to the US earthquake observatory.

A few minutes earlier, a severe earthquake off the coast had already forced residents to leave their homes.

"We all fled our home," 36-year-old Yudi Prama Agustino told AFP.

"I have a one-year-old baby, so in a panic I pushed the stroller out of the house."

Collapsed and damaged homes were seen in images from the town of Pasaman, near the epicenter.

Local authorities said there were cracks in some buildings, which are in danger of collapsing.

Indonesia's weather agency advised people to stay away from slopes due to fears of landslides given the rainy season.

The island state of Indonesia is repeatedly affected by earthquakes because of its location on the Pacific Ring of Fire.