The Turkey's constitutional court challenged the charges, saying they violated freedom of the press, they won the case and were both released early on Friday after three months in jail.
Large crowds chanting support met them outside prison on their release.
Mr Dundar, the paper's editor-in-chief, and Mr Gul, its Ankara bureau chief, spent 92 days in prison and had been due to go on trial on 25 March. He said:
"This is a trial of press freedom," Mr Dundar said. "We got out but more than 30 colleagues are still in prison. I hope that this ruling will pave way for their freedom as well."
"We would continue to fight for press freedom until this concentration camp that you see behind me becomes a museum".The court, which ruled on Thursday agreed that their "rights to personal liberty and security had been violated and that the decision was overwhelmingly approved with 12 votes for and three against, Turkish media reports said.