Ignoring Castillo's attempt to shut down the legislature by decree, lawmakers moved ahead with the previously planned impeachment trial, with 101 votes in favour of removing him, six against and 10 abstentions.
The result was announced with loud cheers on Wednesday, and the legislature called Vice-President Dina Boluarte to take office.
Boluarte was sworn in as president through 2026, making her the first woman to lead Peru. She called for a political truce to overcome the crisis and said a new cabinet inclusive of all political stripes would be formed.
She lambasted Castillo's move to dissolve Congress as an "attempted coup".
Peru's national police shared an image on Twitter of Castillo sitting unrestrained at a police station after the vote to remove him and said that it had "intervened" to fulfill its duties. It referred to Castillo as "ex-president". It was unclear if he had been detained.
Castillo earlier had said he would temporarily shut down Congress, launch a "government of exception" and called for new legislative elections.
That sparked resignations by key ministers from Castillo's government and allegations of a "coup" by opposition members and allies. The police and armed forces warned him that the route he had taken to try to dissolve Congress was unconstitutional.
Peru has gone through years of political turmoil, with multiple leaders accused of corruption, frequent impeachment attempts, and presidential terms cut short.
The latest legal battle began in October, when the prosecutor's office filed a constitutional complaint against Castillo for allegedly leading "a criminal organisation" to profit from state contracts and for obstructing investigations.
Congress summoned Castillo last week to respond to accusations of "moral incapacity" to govern.
Castillo has called the allegations "slander" by groups seeking "to take advantage and seize the power that the people took from them at the polls".
The leftist teacher-turned-president had survived two previous attempts to impeach him since he began his term in July 2021.
But after Wednesday's attempt to dissolve Congress his allies abandoned him, his ministers resigned, and regional powers underlined the need for democratic stability.
"The United States categorically rejects any extra-constitutional act by President Castillo to prevent Congress from fulfilling its mandate," the US ambassador to Peru, Lisa Kenna, wrote on Twitter.
The turmoil rattled markets in the world's No.2 copper producer, though analysts said that the removal of Castillo, who has battled a hostile Congress since taking power, could be a positive for investors.
Peru's sol currency fell more than two per cent against the dollar at its session low before recovering slightly to trade down 1.4 per cent.
"Peru's financial markets will suffer, but won't collapse, thanks mainly to solid domestic fundamentals," said Andres Abadia at Pantheon Macroeconomics.