The candidate of the ruling CCM party, John Pombe Magufuli, leads Tanzania's presidential race after a tally of official results late on Tuesday put him ahead of nearest rival, Edward Lowassa of Chadema and the opposition Ukawa alliance.
Delays in releasing the results, however, continued to stoke tensions and police were deployed in many parts of the country and in parts of the capital, Dar es Salaam, as the anxiety threatened to spill over into violence.
CCM, which has governed Tanzania since independence from Britain in 1961, was also on course to win a reduced majority in Parliament, although the status of Zanzibar remained contested after the opposition claimed it had narrowly won the presidency of the islands for the first time.
With about three million votes announced, Mr Magufuli had polled 1,689,003 votes or 56.68 per cent, ahead of Mr Lowassa who had 41.52 per cent. An earlier tally of fewer results gave Mr Magufuli 64.5 per cent but this had reduced as more results were released.
However, with about 23 million registered voters and with results from many key regions yet to be announced, the figures, which were from 86 out of 264 constituencies, remained inconclusive. Voter turnout, which was only 42 per cent in the last election, was expected to be much higher this time.
More results were expected overnight on Tuesday. Tanzania uses a first-past-the-post method and whoever gets more votes will be sworn in to succeed President Jakaya Kikwete who is stepping down after two terms in office.
There are six other candidates in the presidential race, including the only female, Anna Elisha Mghwira of the ACT party, but they collectively had less than two per cent of the vote by press time.
CCM surged ahead in the parliamentary race, winning 92 out of the first 129 races called with Chadema, at 28, beating its mark of 24 in the out-going Parliament with many more races yet to be called. The Civic United Front, which is part of the opposition alliance, had 8 seats while NCCR-Mageuzi had one. The new Parliament will have 265 seats, up from 239.
Agriculture minister and veteran CCM politician Stephen Wasira was one of many high-profile victims of the country's most competitive election, losing his parliamentary seat to Chadema's Ester Bulaya.
Investment minister Christopher Chiza, deputy health minister Stephen Kebwe and deputy education minister Anna Kilango were some of the other high-profile losers.
Police in Zanzibar fired teargas to disperse opposition supporters after Seif Sharif Hamad declared himself winner of the presidential election on the island, ahead of incumbent and CCM candidate, Dr Ali Mohamed Shein.
Clashes were reported in other parts of the country between rival supporters and with the police, testing Tanzania's reputation for comparatively peaceful political contests on the continent.
African, Commonwealth and European election observers gave their preliminary reports on Tuesday commending the peaceful nature of the polling on Sunday but the EU delegation said the process had not been fully transparent.
The elections "were highly contested, largely well administered, although insufficient efforts at transparency meant that both the National Electoral Commission (NEC) and the Zanzibar Electoral Commission (ZEC) did not enjoy the full confidence of all parties", the EU observers said in a statement.
The head of the EU observer team, Judith Sargentini, said they were "closely following" the dismantling of an opposition election results tally centre and the arrest, on Sunday night, of 191 opposition officials involved in the exercise.
Electoral officials have denied allegations of bias by the opposition in releasing results and said final results will be released by Thursday.