While the Indian National Congress and Gandhi called for the British to quit India, the Muslim League passed a resolution for them to divide and quit, in 1943.
The Mahatma is believed to have been opposed to the partition during independence and suggested an agreement which required the Congress and Muslim League to cooperate and attain independence under a provisional government, thereafter, the question of partition could be resolved by a plebiscite in the districts with a Muslim majority.
When Jinnah called for Direct Action, on 16 August 1946, Gandhi was infuriated and visited the most riot prone areas to stop the massacres, personally.
He made strong efforts to unite the Indian Hindus, Muslims and Christians and struggled for the emancipation of the "untouchables" in Hindu society.
On the 14th and 15th of August, 1947 the Indian Independence Act was invoked and the following carnage witnessed a displacement of up to 12.5 million people in the former British Indian Empire with an estimated loss of life varying from several hundred thousand to a million. But for his teachings, the efforts of his followers, and his own presence, there would have been much more bloodshed during the partition, according to prominent Norwegian historian, Jens Arup Seip.
Stanley Wolpert's words sum up Gandhi's role and views on the partition perfectly:
Their plan to carve up British India was never approved of or accepted by Gandhi, however, who realised too late that his closest comrades and disciples were more interested in power than principle, and that his own vision had long been clouded by the illusion that the struggle he led for India's freedom was a nonviolent one.– Stanley Wolpert, Gandhi's Passion, The Life and Legacy of Mahatma Gandhi, Oxford University Press