The Congress, which successfully snatched Karnataka from the Bharatiya Janata Party (BJP) on the anti-corruption plank, took the decision as it did not want to send out a wrong signal by showing the party was soft on corruption, a party source said.
With the BJP, which did not allow the parliament to run, adamant on the resignation of both the ministers, Gandhi met the prime minister this evening at his official residence.
Later, Gandhi's political secretary Ahmed Patel and Health and Family Welfare Minister Ghulam Nabi Azad also met the prime minister, said the source.
The first to go was Bansal, who was under a cloud after his nephew was arrested by the Central Bureau of Investigation (CBI) for accepting a bribe of Rs.90 lakh for getting a plum Railway Board post to a senior official.
"Yes, I have resigned," Bansal told reporters after leaving the prime minister's residence.
A little later, Ashwani Kumar, under fire for interfering in a CBI probe into the coal blocks allocation, met the prime minister and handed over his resignation.
In his resignation letter, Ashwani Kumar said it was "to put an end to the controversy of public perception of wrong doing,".
He may be moved to a less significant ministry, said sources.
The resignations have been forwarded to President Pranab Mukherjee for his approval.
Besides the two ministers, the BJP has been demanding the resignation of the prime minister himself also as he headed the coal ministry for a duration in UPA I.
Labour Minister Mallikarjuna Kharge, who was in the running for Karnataka chief minister, is tipped to be the next railway minister. The name of Surface Transport Minister C.P. Joshi, who held the railway portfolio briefly before Bansal, was also being considered, said the sources.
The indication that Bansal's fate was sealed came Friday afternoon when Congress spokesperson Bhakta Charan Das told reporters: "We will not tolerate if anybody is found mired in corruption."
Bansal was asked to resign after reports that he had sought divine help (feeding a goat) to save himself, irked the Congress leadership, said the sources.
Both Bansal and Ashwani Kumar remained in office for around six months.
The BJP termed the resignations a delayed step.
"This is a delayed step. Had the ministers resigned a few days ago, the time of parliament would not have been wasted," BJP spokesperson Syed Shahnawaz Hussain said.
"The Congress does not take any decision on moral grounds," he said.
Communist Party of India leader D. Raja said Bansal should have resigned when parliament was in session, which would have allowed legislative business to take place.