The pair have been in prison since July awaiting trial on money laundering charges.
They allegedly received millions of dollars in illegal campaign donations from Brazilian construction giant Odebrecht ahead of the 2011 election.
“Now my thoughts, my heart, are all with my family,” Humala, who led Peru from 2011-2016, told reporters when he left prison four days after winning a green light to do so from the constitutional court. Their lawyer denounced the delay.
The ex-president stopped to greet party loyalists before heading home to be with his wife, who left prison about an hour earlier than him, and three children in Lima.
“We are going to move ahead because we have not committed any crime,” Humala told Nationalist Party supporters, many chanting “Ollanta. Dignity.”
“We are a young party, and we are still in there fighting,” he said, thanking the crowd.
Humala is one of four former Peruvian heads of state caught up in the vast Odebrecht corruption scandal that has engulfed Latin America — although he is the only one who had been jailed so far.
The other three also implicated in the scandal are Pedro Pablo Kuczynski (2016-2018), Alan Garcia (2006-2011) and Alejandro Toledo (2001-2006), who is currently in the United States fighting off Peruvian extradition efforts.
Also under investigation for receiving illegal Odebrecht money: top opposition leader Keiko Fujimori, daughter of ex-president Alberto Fujimori (1990-2000) and the key player in the political power move that ousted Kuczynski from office.