One government soldier also died in a shootout in the town of Maiduguri.
Boko Haram has recently carried out numerous raids on churches and other targets in Nigeria.
The group wants to establish Islamic law in the country, whose large Christian and animist population mainly lives in the south.
On Sunday, the army said it acted on intelligence that a number of Boko Haram members were holding a gathering at a location in Maiduguri.
“Our men mobilised, leading to a shootout. Twenty suspected terrorists were killed while a soldier died in the operation and two others sustained injuries,” army commander told the AFP news agency.
Boko Haram has not publicly commented on the army’s claim.
Most of Boko Haram attacks have been staged in the largely Muslim north, but the group has also targeted churches in central Nigeria.