It affects 1.39 million cars in Europe – 138,000 in the UK – 2.47 million in the US and 1.4 million in China.
It is the biggest single recall since Ford called back eight million vehicles in 1996.
Toyota said there had been no reports of accidents, injuries or deaths as a result of the window problem.
Toyota is also recalling 459,000 vehicles in Japan, 650,000 in Australia and Asia, as well as hundreds of thousands from across the Middle East, and from within Canada and its other, smaller markets around the world.
The number of vehicles being recalled is roughly the same as its sales for the whole of its last financial year.
The carmaker did not say how much the recall would cost.
The range of Toyota cars affected worldwide include certain models of the Yaris, Vios, Corolla, Matrix, Auris, Camry, RAV4, Highlander, Tundra, Sequoia, xB and xD produced between 2005 and 2010.
In the UK, the models affected are the RAV4, Yaris, Auris and Corolla.
It will be contacting drivers with the affected models over the coming weeks and asking them to bring their car in for checks to see if there is a fault.
Toyota said fixing the switch should take about 40 minutes.
The customer services director for Toyota GB, Steve Settle, apologised to customers for the anxiety the problem had caused, but reassured them that tests had shown there was little danger.
“What we’re talking about is the power switch on the driver’s door and there is a very, very outside chance that there could be melting inside the switch,” he said.
“But there are some vehicle agencies around the world that interpret melting as fire. We’ve no evidence of fire and our engineer testing of this item doesn’t reveal any chance of fire.”
Toyota’s reputation was damaged in 2009 by a recall that ended up involving 12 million vehicles, fines from US regulators and an eventual apology from the company’s head.
Toyota has since overcome massive production problems resulting from the disruption caused by tsunami in early 2011, and has returned to its position as the world’s biggest selling car firm.The recall followed problems with accelerator pedals in vehicles, with worries that they could get jammed under floor mats.
However, it has recently seen sales in China plummet as a result of Japan’s territorial dispute with China.
Latest sales figures released earlier this week show Japanese carmakers’ sales to China fell sharply last month, with Toyota’s dropping by almost 50%.