A man from Pakistani-administered Kashmir who entered India illegally is to apply for an Indian passport after officials said he could stay.
Siraj Khan had requested deportation so he could see family in Kashmir again.
However, officials said he should be considered an Indian citizen as India claims all of Kashmir. The case is thought to be the first of its kind.
Kashmir has been divided between the two countries since independence and both claim it in its entirety.
Siraj Khan told the BBC soon after the court hearing that he was happy with the outcome.
"I am also relieved that my three-year-old fight was over and that I can now visit my parents and other family members on an Indian passport," Mr Khan said.
Mr Khan, 30, had applied to the Bombay High Court seeking his own deportation after appeals to the Indian authorities and the Pakistani High Commission to send him back to Pakistan had failed.
Mr Khan, who works as a caterer in Mumbai (formerly known as Bombay), is married to an Indian Muslim woman with whom he has three children.
"I love Mumbai but I love my parents too and I must visit them as soon as my passport is ready," he said.
Mr Khan came to India when he was nine years old, staying first in Rajasthan and then in the northern city of Varanasi before making his way to Mumbai.
He had no passport or any official documentation, which prevented him from leaving the country.
The state government has now promised to issue him a ration card, which is the first step towards issuing other legal documents including his passport.
Last week the Bombay High Court criticised the state and federal governments for "allowing a man, who claims he is from Pakistan-occupied Kashmir and had crossed over to India in 1995, to stay in the country for so long".
Judges at the court said the case had "ramifications on national security" and summoned the state's attorney general to explain how Mr Khan had been allowed to stay in the country illegally.
However, as soon as the hearing began on Monday the state government said it regarded him as an Indian citizen and that therefore all cases against him for being in India illegally should be dropped.
The advocate general of Maharashtra state, Darius Khambata, told the court that Mr Khan should be considered an Indian citizen, since the Indian constitution regarded "Pakistan-occupied Kashmir" as an integral part of India.
He urged the court to drop all cases against Mr Khan and said he was free to apply for an Indian passport.
There has been no reaction from officials in Pakistan, which rejects the suggestion that Pakistani-controlled Kashmir should be regarded as Indian territory.
Mr Khan's lawyer Ejaz Naqvi described the state government's decision as "a landmark outcome".
"Never before has the government accepted a citizen... [from Pakistan-controlled Kashmir] as a citizen of India. This will have a far reaching effect," Mr Naqvi said.
Mr Naqvi said he believed other people living in India in similar circumstances could now ask for Indian citizenship.
Last year the Indian government said in a statement that "more than 700 Pakistanis were given Indian citizenship in the last three years". But most of these were Pakistani Hindu immigrants.
Mr Khan's case may be viewed with interest by other Pakistanis who have been detained for entering India illegally.
The two countries have detained hundreds of each other's citizens for illegally crossing the frontier and for spying, as well as holding prisoners from the three India-Pakistan wars.