In a tweet, Mr Trump said that from 10 June a 5% tariff would be imposed and would slowly rise "until the Illegal Immigration problem is remedied".
President Trump has declared a national emergency to tackle what he claims is a crisis at the US southern border.
Border agents say they are overwhelmed, but critics say they are mishandling and mistreating migrants.
Jesus Seade, Mexico's top diplomat for North America, said the the tariffs would be "disastrous".
"If this is put in place, we must respond vigorously," he told reporters.
During his election campaign and throughout his time in office, President Trump has sought funds to build a wall on the US-Mexico border.
He hoped to divert funds for the barrier under his national emergency declaration, but a federal judge blocked his efforts in May.
What did Trump announce?
In a White House statement, Mr Trump said the tariffs would rise by 5% each month until October 1, when the rate would reach 25%.
The tariffs would stay at that level "unless and until Mexico substantially stops the illegal inflow of aliens coming through its territory", he said.
"For years, Mexico has not treated us fairly - but we are now asserting our rights as a sovereign Nation," the statement said.
The president also took aim at his Democratic opponents, accusing them of a "total dereliction of duty" over border security.
What will the tariffs affect?
Mexico is known for agricultural products like avocados and tequila, but the country is also a major manufacturing hub and home to many major US companies.
The country produces hundreds of thousands of cars every month, and is also home to technology and aerospace companies. It is one of the G20 economies.