Officials say four insurgents and three security guards died. The Taliban say they carried out the attack.
President Hamid Karzai was in the palace, but the target appears to have been the nearby Ariana hotel, which houses a CIA station.
This is the latest in a string of attacks on Kabul in recent months.
Most recently a suicide bomber in the capital targeted a prominent Afghan politician on 18 June, just hours before Nato formally handed security responsibility to the Afghan forces.
With this attack the Taliban infiltrated one of the most
heavily-guarded areas of the capital, with several key buildings such as the
defence ministry and Nato headquarters located very close by.
The Afghan Taliban have showed no sign of abating their assault on security targets, despite last week's announcement that they had set up an office in the Gulf state of Qatar for peace talks.
In another attack on Tuesday, at least 10 civilians, including eight woman were killed when a roadside bomb hit their vehicle in Afghanistan's southern Kandahar province.
President Karzai raised strong objections to the Taliban office, saying the flag and nameplate initially erected at the building showed they were trying to portray themselves as a government-in-exile.
Officials say the High Peace Council, the Afghan government body set up to lead peace efforts, would not take part unless the talks process was "Afghan-led".
News conference
The attack near the presidential palace, in the central district of Shash Darak, began at about 06:30 local time (02:00 GMT).
The militants initially targeted the palace's eastern gate - a few hundred metres from the actual building - where dozens of journalists had gathered for a news conference with Mr Karzai scheduled for 09:00.
Police say the attack was brought to an end just under two hours after the first shots were fired
The BBC's Bilal Sarwary, who was among the crowd of journalists, says they were forced to run for cover as bullets flew overhead.
The journalists heard several explosions, and reports said grenades were being thrown. Tolo TV reported as many as 14 blasts.
Our correspondent says the area around the palace, which is patrolled regularly throughout the day by special forces and intelligence agents, is now under lockdown.
Taliban spokesman Zabihullah Mujahid said in a text
message: "A number of martyrs attacked the presidential palace, defence ministry
and the Ariana Hotel."
The Ariana Hotel is known to house a CIA station.
Kabul's police chief, Ayub Salangi, said the attack was brought to an end just under two hours after the first shots were fired.
Four attackers wearing uniform and carrying fake ID cards began the attack, with one blowing himself up, a defence ministry spokesman told the BBC. They were eventually killed by private security forces attached to the hotel.
The Nato-led International Security Assistance Force, whose headquarters is also not far from the scene of the attack, wrote on Twitter that the Afghan National Security Forces had led "the response efforts".
Last week, Afghan forces assumed security responsibility for the whole of the country for the first time since the Taliban government was ousted in 2001.
International troops will remain in Afghanistan until the end of 2014, providing military back-up when needed.
Are you in the area? Have you been affected? Send us your
comments using the form below.
Send your pictures and videos to yourpics@bbc.co.uk or text them to 61124 (UK) or +44 7624 800 100 (International). If you have a large file you can upload here.
At the scene
It was a close brush with death for a group of nearly 20 Afghan colleagues including myself.
We were at the palace gates to attend a press event with President Karzai - and security restrictions dictated we arrived hours prior to the event. As we waited to get inside, there was suddenly gunfire followed by loud explosions 10-15 metres away. We had found ourselves in the middle of the fighting.
As presidential guards exchanged fire with insurgents, personnel from the Ariana hotel, the home of the CIA for the last 12 years, also returned fire in self defence as their building came under direct fire. The fighting intensified in a matter of minutes. We took what little cover there was near a wall for the next 40 minutes.
An eight-year-old boy, crying and stuck in the fighting on his way to his school, also sheltered with us.
This attack caused no civilian or military casualties but this is a huge propaganda victory for the insurgents as they have managed to infiltrate one of the safest places in the country.