Dilma Rousseff will head a country in the midst of an economic and political boom when she takes office on January 1.
With nearly all of the ballots counted, Ms Rousseff had 56 per cent compared with just under 44 per cent for her centrist rival Jose Serra, the electoral court said.
In a 25-minute victory speech to jubilant supporters in Brasilia, Ms Rousseff said her first promise was to "honour the women" of Brazil and she hoped her win would allow "fathers and mothers to look their daughters in the eyes and say, 'Yes, a woman can'."
Ms Rousseff, 62, the hand-chosen candidate of wildly popular President Luiz Inacio Lula da Silva, will lead a nation on the rise, a country that will host the 2014 World Cup and that is expected to be the globe's fifth-largest economy by the time it hosts the 2016 Olympics. It has also recently discovered huge oil reserves off its coast.
"Starting tomorrow we begin a new stage of democracy," Ms Rousseff said in the southern city of Porto Alegre. "I will rule for everyone, speak with all Brazilians, without exception."
Mr Silva used his 80 per cent approval ratings to campaign incessantly for Ms Rousseff, his former chief of staff and political protege. She has never held elected office and lacks the charisma that transformed Mr Silva from a one-time shoe-shine boy into one of the world's most popular leaders.
Mr Silva was barred by the constitution from running for a third consecutive four-year term. He has batted down chatter in Brazil's press that he is setting himself up for a new run at the presidency in 2014, which would be legal.
Despite Ms Rousseff's win, many voters do not want "Lula", as he is popularly known, to go away.
"If Lula ran for president 10 times, I would vote for him 10 times," said Marisa Santos, 43, selling her home-made jewellery on a Sao Paulo street.
"I'm voting for Dilma, of course, but the truth is it will still be Lula who will lead us."
Mr Silva entered office with a background as a leftist labour leader but he governed from a moderate perspective. Under his leadership, the economy grew strongly and Brazil weathered the global financial crisis better than most nations.
He is loved within Brazil by the legions of poor, who consider the nation's first working-class president one of their own. His social programmes and orthodox economic policies have helped lift 20 million people out of poverty and thrust another 29 million into the middle class.
Ms Rousseff was a key player in an armed militant group that resisted the 1964-1985 military dictatorship and was imprisoned and tortured. She is also a cancer survivor and a former minister of energy and chief of staff to Mr Silva.
Mr Serra, 68, is the former governor of Sao Paulo state and one-time health minister who was badly beaten by Mr Silva in the 2002 presidential election.
Starting tomorrow we begin a new stage of democracy. I will rule for everyone...without exception.