Armed police swooped on an east London mosque after a "masked" gunman entered the building during Ramadan prayers before shooting his weapon outside.