The highest court in Massachusetts ruled Friday that U.S. Bancorp and Wells Fargo erred when they seized two troubled borrowers’ properties in 2007, putting the nation’s banks on notice that foreclosures cannot be based on improper or incomplete paperwork.

Concluding that neither institution had proved it had the right to evict the borrowers, the Supreme Judicial Court voided the foreclosures, returning ownership of the properties to the borrowers and opening the door to other foreclosure do-overs in the state.

Legal experts said that while this ruling did not set a precedent for other states, the outcome will be closely watched across the country because it is the first such ruling from a state’s highest court. Investors viewed the ruling as negative for banks; an index of financial company shares fell almost 1 percent on the day.

“The broad implication is you’ve got to dot your i’s and cross your t’s,” said Kathleen G. Cully, an expert in bankruptcy and lender regulatory law in New York. “You need a proper chain of title, and in both of these cases there was a gap in the chain.”