It is the second time this month that the Trump administration has abruptly fired a prosecutor who was appointed by judges.
The government could appeal or attempt to retry the cases after a judge threw out the indictments
President Donald Trump has repeatedly called for the prosecution of Comey and James, declaring them "guilty as hell".
The BBC's Nomia Iqbal explains the ex-FBI director's day in court where his lawyer said that his client, a critic of President Donald Trump, was being targeted.
Comey has pleaded not guilty after appearing in court to face charges that he lied to Congress five years ago.
Nerves were raw in a hearing that covered much ground, and saw Trump's attorney general go on the attack.
FBI leadership is reportedly in discussions to stage a showy arrest of the bureau's former director next week.
As the US president pushes a crackdown on left-wing groups and openly targets political foes, critics ask where he's taking America
James Comey says he is innocent and the charges are politically motivated, as they follow Trump pressure on prosecutors to act.