Japan's parliament has voted to allow the military to fight overseas for the first time since the end of World War Two 70 years ago.
A vote on the new law was delayed for several hours as the opposition tried to stop the measure coming into force.
Outside, demonstrators rallied in a last-ditch show of protest.
Many Japanese are attached to the pacifist provisions in the constitution which banned fighting overseas.
The bills have already passed through the government-dominated lower house.
The government says that the changes in defence policy are vital to meet new military challenges such as those posed from a rising China.
It wanted to hold the vote before a five-day holiday begins on Saturday. The governing coalition has a majority in both chambers of the Diet, meaning that ultimately the opposition camp was powerless to stop the measure becoming law.
Masaaki Yamazaki, the president of the upper house, said the bills were passed with 148 lawmakers voting in support and 90 against.
More than 200 hours have been spent deliberating the legislation, the Japan Times reported, and its approval by parliament fulfils one of Prime Minister Shinzo Abe's long-held ambitions.
On Thursday, opposition politicians tried to physically delay proceedings ahead of a committee vote on the bills.
Japan's post-World War Two constitution bars it from using force to resolve international conflicts except in cases of self-defence.
Mr Abe's government has pushed for security legislation that would allow Japan's military to mobilise overseas when these three conditions are met:
When Japan is attacked, or when a close ally is attacked, and the result threatens Japan's survival and poses a clear danger to people.
When there is no other appropriate means available to repel the attack and ensure Japan's survival and protect its people.
Use of force is restricted to a necessary minimum.
Critics say the move will violate the pacifist constitution and could lead Japan into unnecessary US-led wars abroad.
Speaking in parliament on Friday, Akira Gunji, of the opposition Democratic party, said: "We should not allow such a dangerous government to continue like this. Prime Minister Abe's security bill is a threat to our legal framework."
Supporters of the measures, which are backed by Washington, insisted they were essential for the defence of Japan and its regional allies, and will permit greater involvement in peacekeeping activities around the world.
Critics have focused on what they say is ambiguity in how the principles of the legislation will be interpreted, and the possibility that future governments will interpret them more broadly.