Spanish Prime Minister Mariano Rajoy has been forced out of office by a no-confidence vote in parliament.
Socialist leader Pedro Sánchez, who filed the motion after Mr Rajoy's party was implicated in a corruption scandal, will become prime minister.
"We're going to sign a new page in the history of democracy in our country," Mr Sanchez said ahead of Friday's vote.
Mr Rajoy is the first prime minister in modern Spanish history to be defeated in a no-confidence motion.
The leader of the conservative People's Party has been prime minister since 2011.
During the second day of debate on Friday, Mr Rajoy admitted facing defeat and told MPs that it has been "an honour to leave a better Spain than I found".
Mr Sánchez secured a majority in the vote after gaining support from various smaller parties, including the Basque Nationalist Party - 180 MPs backed the motion, 169 voted against, with one abstention.
Why was the vote called?
Mr Sánchez says Mr Rajoy, 63, had failed to take responsibility for his party's involvement in the scandal, which hit the headlines again last week after one of its former treasurers was given a 33-year jail sentence.
The High Court in Madrid convicted Luis Bárcenas of receiving bribes, money laundering and tax crimes.
The case centred on a secret campaign fund the PP ran from 1999 until 2005.
Many Spanish voters, exasperated by corruption scandals involving the traditional centre-right PP and centre-left Socialist parties, have abandoned them for newcomers like the left-wing Podemos (We Can) and centrist Ciudadanos (Citizens), as well as regional parties.