It said in a statement that the operation was conducted in coordination with the security forces and the judiciary.
It "resulted in the dismantling of terrorist groups linked to what is known as Wilayat Baghdad (Baghdad province), a part of the terrorist group Daesh," the statement said, using an Arabic acronym for IS.
The intelligence service said the 31 people arrested are IS members from all parts of Baghdad, as well as areas south and north of the capital.
"They confessed to 52 terrorist acts in different areas of our beloved Baghdad in 2014 and early 2015," the statement said.
It said "large quantities of arms, (explosive) belts, silencers, rigged cars and motorcycles, statements, videos of their cowardly operations" were seized.
Signup to our newsletter and follow us on Facebook and Twitter!
The statement does not say exactly when the arrests were made but the spokesman for the intelligence service suggested they were last month.
"The reason for the decrease in attacks in Baghdad over the past three weeks is the arrest of this network," Fahim al-Atraqchi told AFP.
The number of attacks in Baghdad, which at one point last year used to be rocked by car bombs almost every day, has dropped this year.
In October, Iraqi federal and allied forces expelled IS fighters from the Jurf al-Sakhr area, which lies only 50 kilometres (30 miles) to the south of the capital.
Early this year, they took back all of Diyala province, which lies to the northeast, allowing Baghdad to breathe more comfortably.
The years-old nightly curfew on Baghdad was lifted last month.