BAGHDAD — The civil war in Syria is testing Iraq’s fragile society and fledgling democracy, worsening sectarian tensions, pushing Iraq closer to Iran and highlighting security shortcomings just nine months after American forces ended their long and costly occupation here.

Fearing that Iraq’s insurgents will unite with extremists in Syria to wage a two-front battle for Sunni dominance, Prime Minister Nuri Kamal al-Maliki recently ordered guards at the western border to block adult men, even husbands and fathers with families in tow, from crossing into Iraq along with thousands of refugees seeking to escape the grinding war next door.

Farther north, Iraqi officials have another concern, also related to the fighting across the border. Turkish warplanes have stepped up attacks on the mountain hide-outs of Kurdish insurgents galvanized by the war in Syria, underscoring Iraq’s inability to control its own airspace.

The hardening of the antagonists’ positions in Syria — reverberating across Iraq — was made clear Monday at the United Nations when the new special envoy for Syria, Lakhdar Brahimi, gave a bleak appraisal of the conflict to the Security Council and said he saw no prospect for a breakthrough anytime soon.