Taking a page from a Perry Mason script, lawyers for Vice President Al Gore turned an expert witness for Texas Gov. George W. Bush into an ally in their fight for a hand count of contested Florida ballots that could overturn the presidential election.

"You need either a reinspection or a manual recount ... if you've got a very close election," John Ahmann, a mechanical engineer who helped design punch-card voting systems and later sold them to counties in Florida, acknowledged under questioning from Gore attorney Stephen Zack.

The moment came on the closing day of a weekend hearing before Leon County Circuit Judge N. Sanders Sauls, who is considering Gore's challenge of a Nov. 26 certified election vote count that proclaimed Bush the winner by a 537-vote margin. Gore contends that the certification excluded legal votes that, if counted, would change the outcome of the election here.

The judge will decide today whether to grant Gore's request for a hand count of about 14,000 ballots from Miami-Dade and Palm Beach counties, where about 1.1 million ballots were cast, or to side with Bush, who says the ballots have been counted enough and has laid claim to Florida's 25 electoral votes - and the White House.

Sauls permitted three hours of closing arguments last night after presiding over about 18 hours of testimony. He promised to consider the matter overnight before issuing a ruling this morning.

If he finds for the Bush team, it could spell the end of Gore's monthlong struggle to prove that he won the election Nov. 7. Both sides have said they will appeal the court ruling to the Florida Supreme Court.

Ahmann, now a California rancher who wore a western bolo tie and a turquoise ring, testified at first that he "seriously" doubted that a voter "would be unable to push the chad through" because of a buildup of the tiny bits of paper that voters poke out of ballots with a stylus. He said there was plenty of room in the reservoir for chads to be distributed.

But, under questioning from a Gore attorney, Ahmann conceded that he had made a sworn statement in 1981 that voting machines in Miami-Dade County were problematic and could result in inaccurate counts. The Gore campaign is asking for a hand count of 9,000 Miami-Dade ballots that registered no vote for president during a machine recount out of 654,000 cast.

In an Oct. 7, 1981, patent application for an improvement to this sort of machine, Ahmann had sworn that a problem with a plastic part "can and does contribute to potentially unreadable votes because of hanging chads and unpunched cards." He also said then that a machine could be clogged with chads, which could cause problems.

Ahmann conceded that he made those statements and had previously recommended that these voting machines be cleaned of chads after every election.

The Miami-Dade machines have not been cleaned in eight years, according to testimony.

In their closing arguments, lawyers for the two sides took opposing positions on everything from voter error to the intent of the law.

David Boies, the lead Gore lawyer, argued that the law gave the judge broad authority to act and he urged Sauls to exercise it. He said voting machines miss votes, and they did in this election, especially in 9,000 ballots in Miami-Dade County.

"So what needs to be done with those 9,000 ballots? We think the answer is obvious. They need to be counted, they need to be reviewed," he said.

Barry Richard, the lead Bush lawyer, told the judge that Gore had no claim to a recount. He said the lawyers offered no evidence of voter error, malfunctioning voting machines or abuse of discretion by local canvassing boards.

"What gives you a right to manual recount is not chad buildup. It is not hard rubber. It is the decision of the canvassing board," Richard said. "We have not one shred of evidence of any problems with any voting machines in any precincts. I kept waiting for a witness to come in here and say there was a problem somewhere in this state of a magnitude to overturn the count, and there is none."

Lawyers for Bush argue that Gore is not entitled to a hand count without proving that local elections chiefs abused their authority in tabulating the votes. And they contended yesterday that the Gore team had failed to meet that "heavy burden."

Time is running out for Gore, who needs to prove his case before Dec. 12, when Florida chooses its representatives for the Dec. 18 meeting of the Electoral College. With Florida's 25 electoral votes, Bush would have 271 - one more than necessary to win the presidency.

Bush witnesses yesterday included a statistician for hire and two Republican election observers. The observers, both lawyers, charged that employees of the Miami-Dade canvassing board improperly handled ballots during their shipment to Tallahassee.