His rival Abdullah Abdullah came second with 43.56 percent of the vote, the Independent Election Commission said.
Officials said the turnout was more than eight million in the June 14 vote out of an estimated electorate of 13.5 million voters -- far higher than expected.
"The IEC (Independent Election Commission) admits that despite best efforts for a better election, there were some technical mistakes and shortcomings in the process," IEC head Ahmad Yusuf Nuristani told reporters.
"We cannot deny fraud and violations in the process, in some cases some security forces were involved, in other cases senior government officials like the governors or lower-level officials were involved."
Last-minute talks delayed the release of the results by nearly five hours on Monday, as the two campaigns tried to thrash out a deal over fraud allegations that threaten to fuel instability.
Abdullah has vowed to reject the preliminary result, alleging he was the victim of "industrial-scale" ballot-box stuffing, while Ghani has said he won fairly.
Central to the talks is how many of the total 23,000 polling stations will now be put through an anti-fraud audit.
"We agreed for an audit of 7,000 polling stations, but they had other conditions that we couldn't agree with, so for now there is only partial agreement," Ghani's spokesman Daud Sultanzoy said before the result.
Abdullah's spokesman Fazel Sancharaki said: "Our main demand was for the inspection of 11,000 polling stations under the close supervision of the United Nations. Seven thousand polling stations is not enough."
"The negotiations are still ongoing. If they produce a result, we will enter the process, otherwise... we will not recognise it."
Both sides said the UN was involved in the talks, but its spokesman declined to give further details.
Following the preliminary result on Monday, the official result is scheduled for July 24 after a period for the audit and adjudication of complaints.
RA/NJF