Militants attacked and took control of parts of the central Iraq city of Baquba but security forces eventually repelled the assault on Tuesday, army and police officers said.