ISLAMABAD, Pakistan — Pakistanis will go to the polls on Wednesday to elect a prime minister, transferring power from one civilian government to another for only the second time in the nation’s 70-year history.

The election comes at a critical moment for a country of 200 million people and for a region stressed by war. Pakistan is a nuclear state, an antipathetic but important American ally, and one of the largest Muslim-majority countries in the world.

This year’s election could have been an occasion for Pakistanis to celebrate their democracy. Instead, the campaign has been marred by suppression of the news media, accusations of manipulation by the military, a rise in Islamist extremist candidates and a series of attacks on candidates and campaign rallies, including one that killed 151 people.

Here is what you need to know.

Pakistan’s politics have always been messy: The country has routinely toggled between elected governments and military dictatorships, and a prime minister has never completed his or her entire five-year term. But this year’s campaign has been particularly fraught, given the military’s efforts to push the former governing party out of the running.

Despite that manipulation, the election on Wednesday will serve as a kind of referendum on some of the most crucial issues facing the country. Should Pakistan orient its economy toward the West or toward China? Is its democracy robust enough to include extremist candidates who support militancy, or should they be limited? Can the military and the courts be trusted as impartial and objective institutions?

Wedged between Afghanistan, where an American-led war has stretched on for 17 years, and its historic rival India, Pakistan is always at risk of a conflagration. It has served both as a crucial base for American forces fighting in Afghanistan and as a powerful obstacle to those same troops, secretly offering aid and safe harbor to militant groups, including the Taliban and Al Qaeda.

But Pakistan’s problems are not just about regional security — they are also about its ability to provide opportunity for its own people, including a growing class of young and educated Pakistanis. Despite its size and potential, the country’s economy has lagged, and it faces persistent problems with corruption and environmental stress.

As tensions with the United States and other Western countries have intensified — particularly over accusations that Pakistan is not doing enough to curb the Afghan Taliban and other militant groups — Pakistan has increasingly turned to China for aid and support. But that pivot has come with its own problems, including concern over the quickly increasing amount of debt Pakistan is racking up with China.

There are 122 parties fielding candidates in the election. They all promise jobs, social welfare and housing plans. But the overarching theme of the election has become the confrontation between the military and the governing party, the Pakistan Muslim League-Nawaz, or P.M.L.-N. The party accuses the military of intimidating some of its leading figures into defecting to other blocs, and of unfairly supporting a rival candidate, Imran Khan.

Mr. Khan, 65, is a former international cricket star who has promised an alternative to the corruption and the entrenched political dynasties voters associate with the other leading parties. His rivals attribute his surge in the polls to a back-room deal struck with the military, which they claim has worked to undermine the election. Mr. Khan has denied that accusation, chalking up the accusations of meddling to sour grapes.

Mr. Khan, whose success on the cricket pitch made him a household name, has held a seat in the National Assembly for five years but has never run a government. A large number of independent candidates are expected to join his party, the Pakistan Tehreek-e-Insaf, or P.T.I., if it wins.

Nawaz Sharif, a three-time prime minister, was ousted last year by the country’s Supreme Court. He was convicted of corruption and is now in prison after returning from London this month to be arrested. Mr. Sharif says those court decisions were made under pressure from the military, which opposed his attempts as prime minister to reassert control over the country’s defense and foreign policy.

But his family remains politically powerful. His younger brother, Shehbaz Sharif, 66, is the current president of the P.M.L.-N. and hopes to lead the country. Until recently, he was the chief minister of Punjab, the most populous and prosperous of the country’s four provinces and the party’s biggest source of support.

Bilawal Bhutto Zardari, 29, is the scion of one of Pakistan’s most illustrious and star-crossed dynasties. He is the son and grandson of two former prime ministers, Benazir Bhutto, who was assassinated, and Zulfiqar Ali Bhutto, who was executed. His father, former President Asif Ali Zardari, is considered to wield the real power in the left-leaning Pakistan Peoples Party.

The younger Mr. Zardari is not expected to win, but he could potentially play kingmaker if neither Mr. Khan nor Mr. Sharif receives enough votes to form a government.

Pakistan was recently added to the Financial Action Task Force’s “gray list” of state sponsors of terrorism, increasing pressure on the country to crack down on extremist groups. At nearly the same time, however, the country’s electoral commission was paving the way for more candidates with extremist ties to run for office.

Among the parties seeking seats on Wednesday are Allah-o-Akbar Tehreek, the reconstituted version of a party that officials had previously banned, and Tehreek Labbaik Pakistan, which backs the country’s contentious blasphemy laws.