Ferguson, author of several books on economic history, including The Ascent of Money, made the comments at the Altegris investment conference in California on Thursday.
Asked about Keynes' observation that "in the long run we are all dead," Ferguson said that Keynes had been indifferent to the long run because he had no children, and that he had no children because he was gay.
The remarks caused outrage and a storm of protest among economists and the investment community.Daniel Alpert, managing partner of the investment bank Westwood Capital, wrote on Twitter: "Harvard's @nfergus has totally lost it. Bashing #Keynes work because he was gay!(...) Ugh!"
On Saturday, Niall Ferguson posted an apology on Twitter: "I apologize deeply and unreservedly for stupid and tactless remarks about Keynesthat I made."
"I should not have suggested—in an off-the-cuff response that was not part of my presentation—that Keynes was indifferent to the long run because he had no children, nor that he had no children because he was gay. This was doubly stupid," Ferguson wrote on his blog.
"First, it is obvious that people who do not have children also care about future generations," he wrote. "Second, I had forgotten that Keynes's wife Lydia miscarried."
"My disagreements with Keynes's economic philosophy have never had anything to do with his sexual orientation. It is simply false to suggest, as I did, that his approach to economic policy was inspired by any aspect of his personal life. As those who know me and my work are well aware, I detest all prejudice, sexual or otherwise," Ferguson added.
British-born Keynes is considered one of the world's most influential economists for recommending governments expand fiscal policy to boost demand in the economy.
But his legacy has been hotly debated since the financial crisis as countries have tried to reduce debt.
Ferguson isn't new to controversy either. In August 2012, he wrote a cover article for Newsweek magazine, in which he argued President Barack Obama should not be re-elected because he had not kept his promises. Paul Krugman, the Nobel prize-winning economist and New York Timescolumnist, accused Ferguson of misrepresenting the cost of healthcare reform.