Tuesday’s Democratic Primary was just about as dramatic as you can get, with a nail-biting cliff-hanger, a couple of heavy beatings, and a heavy borough loss for a mayoral candidate who had the strong backing of the Bronx Democratic machine and borough president.

The most dramatic race - likely to head into the courts, even with a final recount - was for disgraced former west Bronx Assemblyman Nelson Castro’s seat in the 86th Assembly District.

The vote count was thisclose between the heavily financed and party machine-backed political newbie Victor Pichardo and former district leader Hector Ramirez.

In the central Bronx, 25-year-old Ritchie Torres stomped a field of six other candidates for term-limited Joel Rivera’s seat in the 15th C.D., grabbing 36% of the vote.

Assemblywoman Vanessa Gibson handily beat back seven challengers to fill the Highbridge City Council seat of term-limited and absentee lawmaker Helen Foster.

Council incumbents easily held on to their seats, even with a bit of controversy hanging over Mott Haven Councilwoman Maria del Carmen Arroyo, who beat back challenger Julio Pabon. She narrowly made it on to the ballot after most of the signatures on her nominating petitions, including “Derek Jeter” and model “Kate Moss,” were invalidated.

And Borough President Ruben Diaz Jr. easily trounced challenger Mark Escoffery-Bey, basically assuring Diaz a win in the Nov. 5 general election for a second full term - or a stepping stone to higher office.

Judging by the vote spread across the borough, even with a generally low turnout, mayoral candidate Bill DeBlasio swamped opponent Bill Thompson, despite major joined-at-the-hip backing by the Bronx Democratic machine and Borough President Ruben Diaz Jr.

The biggest cliff-hanger was for the seat formerly held byCastro, caught up in a perjury case and wired as an informant for several years until his recent resignation.

Victor Pichardo was holding a slim 72-vote lead over Hector Ramirez, with the latest total tally 1195 to 1123.

With such a small margin, a key issue in both a recount - and possible court court challenge - could revolve around voting machines not working - some missing levers. Voters instead had to fill out paper ballots, which need to be counted.

“I won this election,” declared Ramirez, who said he planned court action. “I have the numbers!”

“It just doesn’t look right,” one local political source not directly involved said of close vote.

To add to the embarrasment of Bronx Democratic Party Boss Carl Heastie not being able to turn out more voters for Pichardo, he previously suffered defeat in the district, backing Ramirez against Castro. Ramirez had vowed revenge against Heastie for not backing him again.

“County just wasn’t impressive, even though Carl had a lot riding on this,” said the source. “With all the support - party and financial - that Pichardo had , he should have run away with it. To pull that close is not a good indication.”

In the crowded 15th Council District, Torres emerged the victor with help from a robust voting bloc, heavy-hitting support from unions, powerful lawmakers and $200,000 in PAC funds from a real estate industry group.

Though he dubs himself an outsider to the Bronx Democratic establishment, Torres’ profile was raised given his ties to several Bronx pols, including mentor Councilman Jimmy Vacca, where he worked as a staffer.

“I do not have the political connections that my opponents did,” said Torres. “I was not part of a family or a dynasty.”

With a six-figure Council salary waiting for him in January, Torres is now ineligible to stay at the supportive housing apartment that raised several eyebrows in July. He admitted he would have to move once his salary is officially bumped.

The surprise upset in that race was Joel Rivera’s longtime chief of staff, Albert Alvarez, who placed last, despite support from Rivera and his father, local Assemblyman Jose Rivera.