The objective of the study is to assess the distribution of HLA-B genes, HLA-B27 subtypes, HLA-DRB1 and HLA-DQB1 alleles in patients with ankylosing spondylitis (AS) and in control subjects in the Tunisian population and to compare their distribution with that found in other countries. This is a case-control study that included 100 consecutive patients (85 males/15 females) with AS according to the modified New York criteria and 100 control individuals. HLA-B, B27 subtypes and class II (DR and DQ) typing of all subjects was performed by polymerase chain reaction amplification with sequence-specific primers (PCR-SSP). HLA-B27 was found in 62% of patients against 3% in controls (P = 0.0000, OR = 52.6, 15.6 < CI < 166.7). On the other hand, B*07 and B*51 were significantly decreased in comparison with controls (P = 0.01, OR = 0.3, 0.1 < CI < 0.8 and P = 0.0000, OR = 0.2, 0.1 < CI < 0.4, respectively). Eight B*27 subtypes were identified in the AS group, but the most frequent ones were B*2702 (32%) and B*2705 (24%). Among HLA-DRB1 alleles, a significant increase in DRB1*11 was found in comparison with controls (P = 0.01, OR = 2.2, 1.2 < CI < 4.5). However, DRB1*13 had a negative association with AS (P = 0.01, OR = 0.4, 0.2 < CI < 0.8). For HLA-DQB1 alleles, a significant positive association with DQB1*03 was observed in AS group (P = 0.03, OR = 1.8, 1.0 < CI < 3.4). Multivariate analysis by logistic regression revealed that DRB1*11 and DQB1*03 had no direct links with the disease, but were dependent on the presence of HLA-B27. Moreover, B*07 and B*51 seemed to have independently a negative correlation with AS, but DRB1*13 seemed to depend on B*51. Haplotypes carrying B27 were significantly associated with AS and those carrying B*07 or B*51 were negatively correlated with the disease. In conclusion, our study confirms that B27 predisposes to AS while B*07 and B*51 are negatively correlated with the disease.