Twenty people died following explosions at a military checkpoint outside the north-eastern town of Biu.
Troops present at the checkpoint fired back, killing 17 of the insurgents. It is believed they were from Boko Haram.
On Tuesday the group released a video in which Boko Haram's leader, Abubakar Shekau vowed to disrupt Nigeria's elections at any cost.
The 15-minute film was released via the group's newly created Twitter account, prompting some analysts to question whether they had been influenced by Islamic State.
Previous Boko Haram videos were of a lower quality and distributed to journalists on DVD.
Also on Tuesday, a suicide bomber killed four and injured five at a restaurant near a military checkpoint in Potiskum, north-eastern Nigeria.
Meanwhile an attack at an opposition rally in the south of the country killed one police officer and injured four others, while a reporter covering the event was stabbed, according to news agency AFP.
The attack targeted a rally by the All Progressives Congress (APC) - Nigeria's main opposition - in Okrika, a small port town south of Port Harcourt in the heart of Nigeria's oil-producing region.
APC members were waiting for the rally to begin, witnesses said, when there was several explosions and gunfire.
It was not immediately clear who was responsible for the attack. Boko Haram is not known to operate in the region.
There are fears that Nigeria is becoming increasingly unstable ahead of its delayed general election, pushed back from 14 February to 28 March after the military requested more time to curb the insurgency in the north-east.
The Nigerian Human Rights Commission says at least 58 people have been killed in pre-election violence.
President Goodluck Jonathan, who is seeking re-election, has been strongly criticised for his handling of the Islamist insurgency.
He is facing a strong challenge from opposition leader Muhammadu Buhari, a former military ruler.
Nigeria's electoral commission said on Tuesday it had distributed 75% of voter cards to its 68.8 million voters and said it was on track to reach 100% by the delayed election date.

The Crown Prosecution Service said 1,892 cases were dropped at court due to the "significant ill-health, elderliness or youth" of a defendant.
Another 439 cases were abandoned before the suspect was charged.
The CPS said the number of cases dropped for these reasons accounted for 0.3% of all prosecutions in 2014.
Such prosecutions dropped at court were 1,714 in 2013 and 1,402 in 2012. Those dropped before charge were 354 in 2013 and 128 in 2012.
Between January and March this year, 516 were dropped at court and 132 before charge.
The charity Victim Support said it was important that the decision not to prosecute was explained to victims.
Chief executive Mark Castle said: "Victims often fear that they will not be believed, so it can be many years before they come forward.
"It is critical that victims have the reasons behind a decision not to prosecute properly explained to them so that they understand that it does not mean they have not been believed."
The figures - released after a Freedom of Information Act request by the Press Association - did not specify the nature of the suspected offence.
The CPS said the decision to prosecute was made if there was both sufficient evidence and it was in the public interest.
A spokeswoman said: "The Code for Crown Prosecutors recognises that the more serious the offence, the more likely it is that a prosecution is required, and the age or ill-health of a defendant will be taken into account when deciding whether to prosecute."
In the case of former Labour MP Lord Janner, who has dementia, the CPS decided not to pursue historical child sex abuse claims against him.
The decision was overturned following a review, and a fitness to plead hearing is due to take place on 7 December. Lord Janner denies the allegations.
Dozens of people have been killed in suicide attacks in Nigeria.
[NEXT_CONCEPT]
More than 2,000 suspected criminals avoided prosecution in England and Wales last year because of their ill-health or age, figures have shown.