The House of Representatives (DPR), sitting on the last day of its five-year term of office, endorsed the law, although it still needs the approval of outgoing President Megawati Sukarnoputri.
The law comes ahead of the inauguration in October of Indonesia's next president Susilo Bambang Yudhoyono, whose past as a former general has led to concerns that the once-powerful military could regain old strengths.
Hari Sabarno, Indonesia's security minister, told reporters the law would put Indonesia's armed forces, or TNI, on a "steady footing".
But though contentious sections of the bill have been redrafted by the government, activists were concerned the armed forces would still be able to play a role in formulating state policy.
"TNI back to barracks," said a sign carried by student opponents of the bill outside parliament, the Detikcom online news service reported. "DPR don't sell out civil society for your stomachs," read another.
The law says the military commander is responsible to the president but serving military officers are allowed to hold positions in the defence and intelligence bureaucracies.
Kompas daily reported that the law defines the armed forces' roles for wartime and peace, covering military and counter-terrorism operations.
Ibrahim Ambong, head of the DPR committee which studied the bill, was quoted by Kompas as saying that the bill alters a so-called "territorial" role which gives them the right to maintain a nationwide presence.
However with clauses allowing deployment to broadly defined "strategic" areas and no formal revocation of the territorial role, the law appeared to remain ambiguous.
Political scientist Arbi Sanit had denounced the territorial role as creating "a state within a state".
The new law also calls for the government to take over all military businesses within five years. With a shortage of government funding the military has come to rely heavily on its own business enterprises.