The two countries signed a memorandum of understanding (MoU) on cooperation in cyber security.
A second MoU was signed on cooperation in renewable energy.
Three other MoUs were signed on cooperation in organ transplantation, technical cooperation in civil aviation, and between the Foreign Service Institute of India and the Diplomatic Academy of Spain.
Two agreements were also signed on transfer of sentenced persons and waiving of visas for diplomatic passport holders.
Earlier in the day, addressing the media ahead of his talks with Spanish premier, PM Modi said terrorism posed the biggest challenge to the world and the fight against this menace formed a key element of India-Spain ties.
PM Modi arrived in Madrid from Germany on Tuesday on the second leg of his six-day, four-nation tour of Europe that will also take him to Russia and France.
This is the first visit by an Indian Prime Minister to Spain in nearly 30 years since Rajiv Gandhi paid a trip in 1988. PM Modi and the Spanish prime minister last met on the sidelines of the G20 Summit in Turkey in November 2015.