SAO PAULO (Reuters) - Striking food inspectors who had slowed grain exports were ordered back to work by Brazil's attorney general on Friday as demand for soy and corn from Latin America's largest economy increased to head off a global food shortage.

A union representing the inspectors said they would obey the court order, which came after soy and corn exporters turned to local courts to guarantee document clearance on Wednesday.

Drought in the United States, the world's largest corn producer, has decimated corn and soy crops there. Brazil is the world's No. 2 soy producer, and its corn exports rose to 1.7 million tonnes in July from 134,900 tonnes in June.

Inspectors working for the agriculture ministry walked off the job on Monday. They slowed the issuance of mandatory phytosanitary certificates needed for exports, but did not paralyze shipments.

"I'm not sure how to measure the number of ships that have been affected, but ... there are many given the strike is a national movement and not just located in a single port," said one Sao Paulo grains trader who declined to be named.

In a separate strike, government sanitary inspectors have been off the job for nearly three weeks, but they have not visibly increased the ship line-up at Brazil's main ports.

Customs workers, university professors and other federal employees have staged strikes across the country in recent weeks, a growing headache for President Dilma Rousseff who sees workers' demands for higher wages as counter to her goal of invigorating Brazil's economy.

(Reporting by Gustavo Bonato and Caroline Stauffer)