Mariano Rajoy has become the first sitting Spanish prime minister to testify in court as he denied any knowledge of an alleged illegal financing scheme within his Popular Party (PP).
Mr Rajoy said his role at the party was political and strategic, not financial.
The prosecution claims that during the pre-2008 property boom, companies gave former PP lawmakers and civil servants kickbacks in return for contracts.
Mr Rajoy is not accused of wrongdoing.
His request to testify at the trial in the Madrid suburb of San Fernando by video link was denied. But he was seated on the same platform as the judges, not in the traditional witness stand.
Thirty-seven people, including three former PP treasurers, are on trial in the case that centres around the alleged ringleader, businessman Francisco Correa. Correa is already serving a 13-year sentence for influence peddling and bribery, and could face up to 125 years.
The so-called Gürtel case has electrified Spain for years, after being exposed by Ana Garrido, a civil servant in a Madrid suburb.
Mr Rajoy became leader of the PP in 2004 and held senior positions before then. But on Wednesday he testily insisted he had no friendly relations with Correa and "never dealt with party financial matters".
Nonetheless, Socialist leader Pedro Sánchez called for him to resign to retain his "dignity", reported Efe news agency.
Mr Sánchez has described Mr Rajoy as the "primary political leader" at a time of a "generalised climate of corruption".
Mr Rajoy is not personally accused of wrongdoing but his appearance in court remains a major embarrassment for a prime minister who has continually sought to distance himself from the accusations swirling around his party, correspondents say.
Outside the court, some 30 protesters blew whistles and held placards demanding "Justice" and "Make the PP illegal", reported AFP news agency.