Castillo had said he would dissolve the legislature by decree, throwing the country into a constitutional crisis.
Ignoring Castillo's attempt to shut down Congress, lawmakers moved ahead with an impeachment trial, with 101 votes in favour of removing him, six against and 10 abstentions.
The legislature called Vice President Dina Boluarte to take office.
Castillo was detained by security forces, according to images shown in a tweet published by the national police, shortly after the vote.
While it was unclear who would ultimately prevail, Castillo appeared to be losing his grip on power as allies abandoned him and ministers, the armed forces, police and the US ambassador criticised his move to shut down Congress outside normal legal channels.
"The United States categorically rejects any extra-constitutional act by President Castillo to prevent Congress from fulfilling its mandate," the U.S. ambassador to Peru, Lisa Kenna, wrote on Twitter.
Peru, which has gone through years of political turmoil, has seen major stand-offs between the president and Congress before.
President Martin Vizcarra dissolved Congress and was later impeached in 2020. Three decades ago, former president Alberto Fujimori, currently in prison for human rights abuses and corruption, also announced the dissolution of Congress.
- Reuters