BBC political editor Laura Kuenssberg said the intervention was interesting because a few weeks ago German sources were saying privately that Mrs Merkel wasn't minded to say anything about the referendum.
Speaking during a news conference with Nato General Secretary Jens Stoltenberg in Berlin, Mrs Merkel said: "Obviously, it is up to the citizens of the UK themselves how they wish to vote on the upcoming referendum. I've said repeatedly before that I personally would hope and wish for the UK to stay part and parcel of the EU."
Analysis: BBC Berlin correspondent Jenny Hill
Angela Merkel has been reluctant to intervene in the referendum debate. She's made no secret of the fact that she wants Britain to stay in the EU; it's an important economic and political ally for Germany.
But she's understood to be concerned about how any comments might be interpreted by British voters. Which is why today's intervention is interesting. Mrs Merkel was relatively cautious. She was careful to emphasise that this is, after all, a British decision.
And then - in characteristically guarded language - a warning. The EU, she said, would never compromise with an outsider in the same way it would with a member state.
Mrs Merkel's comments may have been timed to coincide with those of other European leaders who've made it plain that they'd be in no hurry in the event of a Brexit to help the UK renegotiate rights and access. But her intervention certainly reflects a growing unease in Berlin that a Brexit has become a realistic possibility.
She said: "We work well together with the UK particularly when we talk about new rules for the EU.
"We have to develop those together with the UK and whenever we negotiate that, you can much better have an influence on the debate when you sit at the bargaining table and you can give input to those negotiations and the result will then invariably be better rather than being outside of the room."
She stressed the importance of the single market - a free trade area which also includes the free movement of goods, people and capital - and said countries outside the EU "will never get a really good result in negotiations".
Trade and economy
How trade and the UK's economy are affected by membership of the EU.
What the leave and remain sides are saying about trade and the economy in the #EUref campaign
About half of UK overseas trade is conducted with the EU
The EU single market allows the free movement of goods, services, capital and workers
Trade negotiations with other parts of the world are conducted by the EU, not individual member states
UK companies would be freed from the burden of EU regulation
Trade with EU countries would continue because we import more from them than we export to them
Britain would be able to negotiate its own trade deals with other countries
Brexit would cause an economic shock and growth would be slower
As a share of exports Britain is more dependent on the rest of the EU than they are on us
The UK would still have to apply EU rules to retain access to the single market
EU referendum issues guide: Explore the argumentshttp://www.bbc.co.uk/news/uk-politics-eu-referendum-36027205http://www.bbc.co.uk/news/special/2016/newsspec_13606/content/iframe/english/index.inc.app.htmlExplore all the issuesChoose an issue:What both sides are sayingAll issuesMain viewsShare this pageEU referendum issues guideWhat the leave and remain sides are saying in the #EUref campaign
"It would be not only be in our interest but it could also be in the interest of Britain when it can bring its whole political weight to the negotiating table as part and parcel of the EU."
Labour MP and Leave campaigner Kate Hoey told the BBC Mrs Merkel would be "well advised to stay out of what is a very, very important vote for British democracy".
"I really don't think that Angela Merkel telling the British people how they should vote in a democratic referendum in three weeks time will affect anyone's vote," she said.
"We can do extremely well outside the European Union - we don't need to be in the single market, other countries trade with the European Union and are not in the single market. We are the fifth largest economy, we can look outwards."
Mrs Merkel is the latest EU leader to speak out about the UK's referendum as the campaign enters its final weeks. On Wednesday, Dutch PM Mark Rutte warned of a tit-for-tat response if the UK were to implement a points-based immigration system while on Thursday, Spanish PM Mariano Rajoy warned that the consequences of an exit vote would be "very negative for British citizens".