ISLAMABAD, Pakistan — The government here cemented its grip on power on Friday with strong gains in Senate elections that represented a psychological victory for the beleaguered president, Asif Ali Zardari , and should ensure his party’s influence for another three years. 
 
 By late evening, the governing Pakistan Peoples Party and its coalition allies had won 32 of 49 possible seats; another 5 seats were to be announced, but the result could not prevent the government from taking control of the upper house of Parliament. 
 
 It was an important milestone for Mr. Zardari and his supporters, who only a few months ago were dogged by sporadic speculation of a military coup and threats from assertive judges and lurid political scandals. 
 
 Those dangers have not entirely abated, but the Senate victory showed that Mr. Zardari’s party — whose supporters not long ago warned of a “soft coup” — has greater staying power than its critics ever imagined. 
 
 “This is a huge boost for the P.P.P.,” said Cyril Almeida, a senior columnist with Dawn, Pakistan’s biggest English-language newspaper. “At a time when few people believed this government would survive, they have managed to pull it off.” 
 
 Now Mr. Zardari’s party will dominate the upper house until March 2015, giving it the power to block legislation — even if it is defeated in general elections, which are scheduled for February 2013, but which analysts expect this fall. “This election is the result of political maturity, from all the parties,” said Senator Raza Rabbani of the Pakistan Peoples Party, one of the winners, on Friday evening. 
 
 The government is not in the clear yet. The prime minister, Yousaf Raza Gilani, faces contempt charges as part of a Supreme Court corruption investigation. He could also be jailed for six months and barred from public office. The economy is in a chronic state of disrepair and, in the northwest, Islamist militants are pressing their violent campaign. 
 
 Two bloody clashes on Friday in the Khyber tribal agency, along the Afghan border, underscored the challenge facing Pakistan’s leaders. A predawn assault by dozens of fighters from Lashkar-e-Islam, a local militant group, on a government security post killed 10 soldiers and 23 militants, said a local security official who spoke anonymously. 
 
 Hours later, Lashkar-e-Islam itself came under attack when a suicide bomber blew himself up outside the group’s base in the Tirah Valley, killing another 23 people, the local administrator, Mutahirzeb Khan, said. Officials speculated that the bomber had been sent by a rival Islamist militia, possibly the main Pakistani Taliban group. 
 
 Mr. Zardari’s Senate triumph arrived as the theatrical scandal that gripped the political system just a few months ago appeared to be fizzling out. 
 
 Last fall, Mansoor Ijaz, an American businessman of Pakistani origin, caused a sensation with claims that he had written a private memo to the United States government last May, on behalf of Mr. Zardari, requesting American assistance in the event of a military coup. 
 
 Mr. Ijaz said the government had offered to neuter the powerful Inter-Services Intelligence Directorate in return for American help — a claim that set off fury inside the military, whose leaders have long distrusted Mr. Zardari, and which led to the formation of a judicial commission of inquiry that started work in January. 
 
 But although the scandal cost the job of Hussain Haqqani, Pakistan’s ambassador to Washington whom Mr. Ijaz accused of complicity in the memo, it failed to produce the promised fireworks that would damage the government. After initially refusing to travel to Pakistan to testify, citing security concerns, Mr. Ijaz finally gave evidence via video link from London this week. 
 
 But he failed to produce hard evidence to back up his earlier allegations, although he did make fresh attacks on the president. Citing “intelligence sources,” Mr. Ijaz told the commission on Friday that Mr. Zardari had prior knowledge of the American Special Forces raid in May that killed Osama bin Laden. ||||| A Pakistani official says a suicide bomber has killed 23 people, many of them believed to be militants, in an attack on the base of a rival insurgent group. 
 
 An aged man drags a cart carrying disposable containers to earn his living in Peshawar, Pakistan on Thursday, March 1, 2012. (AP Photo/Mohammad Sajjad) (Associated Press) 
 
 Friday's bombing took place in the Tirah Valley region close to the border with Afghanistan. 
 
 Political administration official Iqbal Khan says the target of the bombing was the base of the Lashkar-e-Islam group. He didn't immediately know how many of those killed were militants and how many were civilians. 
 
 A commander of the Pakistani Taliban, which is a rival of Lashkar-e-Islam, claimed responsibility for the attack in a call to an Associated Press reporter. The commander gave his name as Mohammed. 
 
 Both groups have been fighting for control of the Tirah Valley. 
 
 THIS IS A BREAKING NEWS UPDATE. Check back soon for further information. AP's earlier story is below. 
 
 ISLAMABAD (AP) _ Pakistani intelligence officials say clashes between the military and Islamist militants have killed seven troops and 20 insurgents in a northwest region close to the border with Afghanistan. 
 
 The clashes broke out Friday in the Khyber region. The militants and the army have been battling for control there for several years in on-and-off skirmishes. 
 
 Intelligence officials say Friday's fighting was taking place in the Tirah Valley area. They spoke on condition of anonymity because they are not authorized to talk to the media. 
 
 It was not possible to independently confirm the figures because the region is off-limits to journalists. 
 
 Pakistani security forces are battling militants in several parts of the border region with Afghanistan.
– The Pakistani militant group Lashkar-e-Islam is sometimes described as part of the broader Taliban movement, but if so there's trouble in paradise. A Taliban suicide bomber reportedly attacked a Lashkar-e-Islam base in the Tirah Valley today, killing 23 people, Pakistani officials tell the AP. It's unknown how many of those killed were civilians. It was a bloody day for Lashkar-e-Islam, which also launched a major attack on a Pakistani military hilltop security post. That attack resulted in a pitched battle that left 10 soldiers and 23 militants dead, the New York Times reports. The Pakistani military is in the midst of an offensive into the Khyber region, in an attempt to push Lashkar-e-Islam out of the Bara subdistrict that is uncomfortably close to Peshawar. Officials say they were expecting the hilltop post to be attacked, because it is strategically located between Bara and the Tirah Valley, Lashkar-e-Islam's traditional stomping grounds.