In 2013, Mr. Rajoy called the slush fund documents “apocryphal,” and he stuck to a similar line on Wednesday. He said he was never informed about any illegal donation made to his party, and that he had “never been in charge of economic matters within the party.”

Even as corruption scandals have swirled around his party, Mr. Rajoy was able to begin a second term in office last October. Two inconclusive general elections have left him leading a minority government. Mr. Rajoy succeeded in obtaining a banking bailout from the European Central Bank during his first term in office, but his parliamentary support is far more fragile now. Still, Spain’s economic recovery has put the country at the forefront of Europe’s growth this year, with unemployment down to under 18 percent from a peak of 27 percent during the financial crisis.

Mr. Rajoy testified on Wednesday as an individual Spanish citizen rather than as head of government. His lawyers tried unsuccessfully to arrange for him to testify by video link rather than in person, citing the demands of his office and concerns over courtroom security. The court did not approve that idea, but did make one concession to Mr. Rajoy’s status, allowing him to sit on the same platform as the judges while testifying, rather than sitting below and facing them.

In a note to investors this week, Antonio Barroso, an analyst at Teneo Intelligence, a consultancy in London, said that Mr. Rajoy’s court appearance would create unwanted headlines but would have little political impact in Spain, in part because the agenda there is now dominated by the issue of Catalan separatism.

The regional Parliament in Catalonia approved legislation on Wednesday to help the region hold a referendum on independence and then put its result into force. Catalan separatists want to hold the referendum on Oct. 1, despite determined opposition from Mr. Rajoy’s government and from the Spanish courts, which view the Catalan referendum as a violation of Spain’s Constitution.