Japan's refuelling mission has proved controversial at home
The Japanese parliament has approved a year-long extension of the country's support for the US-led military operation in Afghanistan.
The bill has proved controversial in Japan, with opponents claiming it contravenes the pacifist constitution.
The government had feared a failure to extend the mission might damage ties with the US, its closest ally.
The mission provides fuel and logistical support for American forces operating in the Indian ocean.
Japan's post-war constitution, which was drafted by the US, places strict limits on the country's overseas military activities.
The mission supporting US warships came to a temporary halt last year, when the opposition used its majority in the upper house to block the bill's renewal.
Japanese forces, who are operating in the Indian Ocean under harsh circumstances, make Japan proud
The bill was only finally approved when the ruling coalition in the lower house over-ruled the upper house after a period of parliamentary ping-pong.
Friday's vote provided some respite for the beleaguered prime minister, Taro Aso, whose approval ratings have recently fallen to 20%.
"We will assume our responsibility in the international community by continuing our part in the war on terror through the refuelling mission," Mr Aso said in a statement.
"Japanese forces, who are operating in the Indian Ocean under harsh circumstances, make Japan proud," he added.
But some opposition members remain unhappy about the mission, with Communist Party lawmaker Seiken Akamine telling reporters: "We should stop being under the US thumb by continuing to support this war."
Mr Aso had been concerned that a failure to renew the mission would damage relations with the US and, crucially, President-elect Barack Obama, who has made Afghanistan a foreign policy priority.
Outgoing US ambassador to Japan, Thomas Schieffer, welcomed parliament's decision.
In a statement, Mr Schieffer said, "As a leading member of the international community, Japan has an important role to play in... efforts to support a stable, democratic Afghanistan and in the fight against terrorism."
The extension of the mission came as the government announced it would end its operations in Iraq by the end of the year.
Japan deployed around 600 troops to southern Iraq on an humanitarian mission from 2004 to 2006, then replacing it with an airlift mission.
Mr Aso's poor public standing has raised questions over whether he can maintain a grip on power until the next election, which must take place before September 2009.