REYKJAVIK, Iceland — Iceland’s prime minister announced on Sunday that he would resign, as the insurgent, anti-establishment Pirate Party capitalized on a wave of anger over corruption to come in second place in the country’s general election.

The prime minister, Sigurdur Ingi Johannsson, announced his departure on national television after his center-right Progressive Party’s share of seats in the 63-seat Parliament collapsed to eight from 19 in the previous election, in 2013.

Mr. Johannsson’s predecessor as prime minister, Sigmundur David Gunnlaugsson, was forced from office in April amid accusations of conflicts of interest after revelations in leaked documents, known as the Panama Papers, of the hidden wealth of the country’s elite.

The conservative Independence Party, which has been in a governing coalition with the Progressives, came in first with 21 seats, up from 19 in the last election.