Friends in Karachi had me over for a beer Sunday evening. It wasn't hard for them to do. Alcohol is broadly outlawed in Pakistan, but with so many exceptions and so little enforcement, you can usually find something — in this case, tallboy cans of Murree's Millennium Brew from a Pakistani brewery.

Several of my friends were fathers, raising kids in a city where the number of homicides exceeded 2,000 last year. They told me they're not comfortable letting their younger children go out to play. Instead the kids play cricket, the national obsession, in apartment building hallways. One father is holding off buying furniture so his kids can push their bikes around the dining room.

Our talk came just after the Karachi Literature Festival, where a famously violent city put on a different face. Writers from Pakistan and other nations gathered beneath a giant tent, on a green lawn by the waterside at the Beach Luxury Hotel. (I was honored to be invited, having written a book about Karachi called Instant City.)

Any literary event would risk being irrelevant in a place as troubled as Karachi. Yet this festival was intensely relevant. The most prominent Pakistani novelists to emerge in recent years have made their country's crisis central to their art.

In a panel discussion, novelist Mohsin Hamid said he couldn't imagine separating politics and fiction. His The Reluctant Fundamentalist depicted a man's drift toward extremism; his forthcoming novel is called How to Get Filthy Rich in Rising Asia. Other sessions included Mohammed Hanif, who fills his darkly comic novels with power-mad generals and corrupt cops like those he covered as a journalist. Hanif was at the festival to introduce his new nonfiction work: profiles of Pakistanis who have disappeared as the government tries to crush an insurgency in the province of Baluchistan. His gut-punch of a book begins with a 4-year-old being shown the bullet-riddled body of his father.

Discussions at the festival were as intense as the writing. Organizers arranged an onstage talk with Cameron Munter, who until recently was the U.S. Ambassador, the representative of Pakistan's profoundly unpopular ally. Even people at this Western-leaning event had doubts about American policies, and a standing-room-only crowd hurled raw questions at the ambassador. "You're not serious" about nurturing Pakistan's democracy, a woman in the audience declared. It's true that America has collaborated with military rulers, and has struggled to support the elected government in power today.

Munter's reply was equally true. The United States can never give democracy to Pakistan, he said; it must come from within: "Pakistan has to lead."

But lead where? As Mohsin Hamid said in a different discussion, "It's frighteningly obvious that [Pakistanis] don't agree what Pakistan should be." The country has a democratic tradition, and also a tradition of degrading it. Citizens have differed from the nation's founding on the role of Islam in this Islamic republic. Educated elites, like those at the festival, are connected to the global economy, while some Islamists are connected to global extremists. Islamist parties never win a national election, but are intimidating enough that governments cave in to religious rhetoric.

The result is often a messy compromise, such as the ban on alcohol: Pass a law to appease the pious, but apply it in a way that lets people do what they want.

The art of politics, of course, is to compromise while keeping a higher goal in sight, the way the president does in the movie Lincoln. In Pakistan, higher goals often recede. Ugly compromises get people killed. Years ago, the government banned extremist groups that it had previously nurtured. But the groups continued operating under new names, making the extremist ban about as effective as the alcohol ban. In 2010, I visited leaders of the group formerly known as Sipah-e-Sahaba who still advocated branding Pakistan's minority Shiite sect as apostates. Other groups share this idea, and Shiites have been assassinated for years. It's no surprise that Pakistani novels are so edgy when the novelists live with realities like that.

The Karachi Literature Festival coincided with a mass murder of Shiites. A bomb killed more than 80 people in the western city of Quetta. The news distressed Karachi's many Shiites, who vowed to shut down the city in protest. By Sunday shopkeepers were slamming down their gates out of fear of violence. On Monday mass transit and many schools were closed, and one of the largest cities in the world began grinding to a halt. My friends' children were condemned to another day indoors, whacking the cricket ball against the walls.

At 3:45 Monday morning, with the festival complete, my hotel arranged for a driver to take me to the airport. Partway there we had to stop. We saw flames in the darkness ahead. Shiite protesters had blocked the airport road with burning garbage, heavy trucks and what appeared to be an overturned police kiosk. My driver weaved through darkened neighborhoods in search of an alternate route, only to encounter one Shiite roadblock after another.

Then came one of the compromises with which Pakistanis manage the contradictions of their lives. At one of the roadblocks, a protester politely informed my driver that while the airport highway was blocked, the access road beside it was not. We made it to the airport in time. I boarded the plane marveling at a country that still just barely manages to function, and hoping that my friends will find the narrow road ahead.