By Ruma Paul

DHAKA (Reuters) - Police in Bangladesh killed nine militants on Tuesday who were believed to have been plotting an attack similar to the one on a cafe on July 1 that killed 22 people, the national police chief said.

Police said the militants, holed up in a building in Kalyanpur on the outskirts of the capital, Dhaka, opened fire on officers as they tried to enter.

The militants, who shouted "Allahu akbar" or "God is greatest" as they battled police, were believed to be members of the banned group, Jamaat-ul-Mujahideen Bangladesh (JMB), which has pledged allegiance to Islamic State.

"They were wearing black outfits, turbans and had backpacks ... similar to the outfits the attackers in the cafe had," police chief Shahidul Hoque told reporters at the scene after the militants were killed.

"They were plotting a major attack in the capital like that in the restaurant."

One wounded militant was captured and another managed to escape, he added.

"The militant who was detained claimed they were Islamic State members, but we think they're JMB," Hoque said.

The detained militant, identified as Raqibul Hasan, went missing for a year after joining a coaching center to prepare for medical entrance exams in the northern district of Bogra, home to two of the five cafe attackers.

Dhaka city police chief Asaduzzaman Mia said police were questioning the owner of the building, from which they had seized weapons and a huge quantity of explosive gel.

"Primary evidence suggests they were well educated and from well-off families," he told a news conference, referring to the militants in Tuesday's incident.

Intelligence reports prompted the police raid, said Prime Minister Sheikh Hasina, adding, "They were preparing to carry out a terror attack."

Islamic State (IS) claimed responsibility for the cafe assault, one of the worst militant attacks Bangladesh has ever suffered, but the government dismissed suggestions the group had a presence there.

Police said JMB was behind the attack by five young Bangladeshis on the upmarket cafe. Most of the 22 killed were foreigners and the five attackers were also killed.

In the past year, Al Qaeda and Islamic State have made competing claims over the killings of liberals and religious minorities in the mostly Muslim nation of 160 million people.

While authorities blame the violence on domestic militants, security experts say the scale and sophistication of the cafe assault suggested links to a trans-national network.

Islamic State has warned violence will continue until Islamic law is established worldwide.

(Additional reporting by Serajul Quadir; Editing by Robert Birsel and Clarence Fernandez)