The bill proposes to toughen penalties for terrorism offences and give judges and police new powers to prosecute "lone wolf" radicals and those who join armed groups in war zones such as Syria.
Conservative Prime Minister Mariano Rajoy and the leader of the opposition Socialist Party, Pedro Sanchez, signed the joint reform bill, which must now go to parliament for approval.
"We are adopting better judicial and operational tools to guarantee the freedom and security of Spanish citizens," Rajoy said in the televised signing ceremony.
Sanchez said it was an "indispensible accord to improve our capacity to prosecute and fight against jihadist terrorism".
The government had been promising anti-terrorism reforms for months but Monday's pact was drawn up swiftly after the deadly jihadist attacks in Paris which left 17 people dead.
The Socialists opposed the ruling Progressive Party's (PP) bid to end limits to life sentences in serious cases such as terrorism.
That measure was left out of the new pact, but it features in another PP penal reform bill pending in parliament, where the party holds a majority.
The joint party pact proposes to crack down on online recruitment and training of extremists and financing of terrorist groups, according to details released by Rajoy's office.
It allows for prison sentences for convicts who travel to areas "controlled by a terrorist group" for training or who plan to join such a group.