(Adds comments by Temer, finance minister, background)
BRASILIA, June 1 (Reuters) - Brazil's economy emerged from its worst recession on record with its fastest growth rate in nearly four years, data showed on Thursday, boosting President Michel Temer's case for staying in office as he battles a corruption scandal.
Brazil's gross domestic product (GDP) grew 1.0 percent in the first quarter from the preceding one, matching economists' forecasts for the biggest rise since the second quarter of 2013.
Temer, who has resisted protests for his resignation after being placed under investigation by the Supreme Court, tweeted minutes after the release: "The recession is over!"
"It's the result of the measures we are taking. Brazil is growing again and will grow even more with the reforms," he went on. He was referring to a legislative agenda seen as crucial for balancing the budget but which got stuck in Congress as his allies debated whether to break ranks with the government.
Fourteen million workers remain unemployed in Brazil, a country with one of the biggest gaps between the wealthy and poor. Many analysts expect Latin America's largest economy, operating now at 2010 levels and forecast to grow just 0.5 percent in 2017, will continue running below potential throughout next year at least.
"There is still some way to go before a full recovery but we're in the right direction," Finance Minister Henrique Meirelles said in a statement praising what he called a "historical day" for Brazil.
The fastest increase in agricultural output since 1996 led the rebound, following bumper harvests of soy and corn. Services remained stagnant and manufacturing grew only slightly in the first quarter, driven up by stronger exports, IBGE said.
Brazil's economy shrank more than 3 percent in each of the past two years, the deepest and longest downturn since records began in 1901. As the recession deepened last year, Temer's predecessor, Dilma Rousseff, was impeached for breaking budget rules amid record-low approval ratings.
Temer's hold on power seemed in danger two weeks ago when the billionaire owners of meatpacker JBS SA accused him of condoning bribes to silence a key witness in a corruption probe. But lack of a clear replacement and signs of economic growth have given the scandal-plagued president some breathing room, allies have said.
IBGE also revised up fourth-quarter data to show that Latin America's largest economy contracted 0.5 percent in that period, and not 0.9 percent as originally reported.
Brazil's economy shrank 0.4 percent in the first quarter from the year-earlier period, following a 2.5 percent drop in the previous quarter. (Reporting by Silvio Cascione; Editing by W Simon and Chizu Nomiyama)