Socialist Nicolas Maduro, hand-picked successor of the late leader Hugo Chavez, has won a narrow victory in Venezuela's presidential poll.
Mr Maduro won 50.7% of the vote against 49.1% for opposition candidate Henrique Capriles.
Mr Capriles has demanded a recount, saying Mr Maduro was now "even more loaded with illegitimacy".
He said there were more than 300,000 incidents from Sunday's poll that would need to be examined.
Announcing the results late on Sunday night, the National Electoral Council said they were "irreversible".
As the news emerged, celebrations erupted in the capital, Caracas, where Mr Maduro's jubilant supporters set off fireworks and blasted car horns. Opposition voters banged pots and pans in protest.
In a victory speech outside the presidential palace, Mr Maduro, wearing the colours of the Venezuelan flag, told crowds that the result was "just, legal and constitutional".
He said his election showed Hugo Chavez "continues to be invincible, that he continues to win battles''.
Mr Maduro said he had spoken to Mr Capriles on the phone, and that he would allow an audit of the election result.
He called for those who had not voted for him to "work together" for the country.
But Mr Maduro's margin of victory was far narrower than that achieved by Chavez at elections last October, when he beat Mr Capriles by more than 10%.
Almost immediately one member of the National Electoral Council who does not have government sympathies called on the authorities to carry out a recount by hand, a call later echoed by Mr Capriles himself.
At Mr Capriles' campaign headquarters the mood was sombre, as his supporters watched the results on television. Some cried, while others hung their heads in dismay,
Shortly afterwards, Mr Capriles emerged, angry and defiant.
"It is the government that has been defeated," he said. Then, addressing Mr Maduro directly, he said: "The biggest loser today is you. The people don't love you."
The new president faces an extremely complex task in office, says the BBC's Central America correspondent, Will Grant.
Venezuela has one of the highest rates of inflation in the region and crime rates have soared in recent years, particularly in Caracas. Food shortages and electricity blackouts are also common.
But perhaps Mr Maduro's biggest challenge will be trying to govern a country which is so deeply divided and polarised, and where the opposition say they have an increasingly legitimate stake in the decision-making process, our correspondent says.
The closeness of the race has also caused reflection inside Mr Maduro's own United Socialist Party (PSUV).
The man considered to be Mr Maduro's main rival, National Assembly President Diosdado Cabello, tweeted that the results "oblige us to make a profound self-criticism".
Mr Maduro had been serving as acting president since Mr Chavez died of cancer on 5 March.
He is due to be sworn in on 19 April and serve until January 2019 to complete the six-year term that Mr Chavez would have begun in January.
Mr Chavez was a divisive leader. To his supporters he was the reforming president whose idiosyncratic brand of socialism defeated the political elite and gave hope to the poorest Venezuelans.
He effectively used his country's vast oil reserves to boost Venezuela's international clout, and his strident criticism of the US won him many political allies in Latin America.
However, his political opponents accused him of being an autocrat, intent on building a one-party state.